3

Working in a C# WebApp project which I've inherited. I have a couple function definitions as so...

public static DataTable ExecuteDT(this AppDBContext target, string sql, int timeoutSeconds = defaultTimeoutSeconds) {
    DbCommand cmd = target.Database.Connection.CreateCommand();
    cmd.CommandText = sql;
    cmd.CommandType = System.Data.CommandType.Text;
    if (timeoutSeconds != defaultTimeoutSeconds) cmd.CommandTimeout = timeoutSeconds;

    DataTable rv = new DataTable();
    rv.Load(cmd.ExecuteReader());
    return rv.Copy();
}

public static object ExecuteDR(this AppDBContext target, string sql, int timeoutSeconds = defaultTimeoutSeconds) {
    DataTable dt = target.ExecuteDT(sql, timeoutSeconds);
    return (ReferenceEquals(dt, null) || dt.Rows.Count == 0) ? null : dt.Rows[0];
}

When I do a Build on the application, it compiles fine with zero errors.
However, when I try to run the website (using F5), it launches in my browser, and then comes up with a compile error:

Compiler Error Message: CS0121: The call is ambiguous between the following methods or properties: 
'ConstructionLoan.WebFormsApp.DataExtensions.ExecuteDT(ConstructionLoan.Domain.Data.AppDBContext, string, int)' and 
'ConstructionLoan.WebFormsApp.DataExtensions.ExecuteDT(ConstructionLoan.Domain.Data.AppDBContext, string, int)'

Source Error:

Line 34: 
Line 35:         public static object ExecuteDR(this AppDBContext target, string sql, int timeoutSeconds = defaultTimeoutSeconds) {
Line 36:             DataTable dt = target.ExecuteDT(sql, timeoutSeconds);
Line 37:             return (ReferenceEquals(dt, null) || dt.Rows.Count == 0) ? null : dt.Rows[0];
Line 38:         }


Source File: c:\Users\myuser\Source\Workspaces\ourclient\src\Web\Main\ConstructionLoan.WebFormsApp\App_Code\DataExtensions.cs    Line: 36 

It is complaining about the same exact function being ambiguous with itself. I have done a search through all of the source code, and this is the one and only declaration of this function, so I am really scratching my head as to what the compiler is getting confused over.

The only question I found on Google that was similar to this was someone who's project had somehow wound up referencing itself. I double-checked to make sure that this project is not referencing itself, and it is not.

I've also tried doing a Clean and Rebuild of the project.

For whatever reason, this project compiles fine in the IDE, but when attempting to run it in the browser it craps out.

I'm working in VS 2015, and targeting the 4.5.2 version of the Framework.

eidylon
  • 7,068
  • 20
  • 75
  • 118
  • 3
    Have you tried deleting the contents of `Temporary ASP.NET files`? Sometimes a previous version of a DLL gets stuck there and it interferes with a newer set of binaries when the compiler is doing its magic. – xxbbcc Nov 09 '15 at 19:32
  • FYI: source files in [App_Code are compiled by ASP.NET at run-time](https://msdn.microsoft.com/en-us/library/vstudio/t990ks23(v=vs.100).aspx). 'You can store source code in the App_Code folder, and it will be automatically compiled at run time.'. You can pre-compile these using the [ASP.NET Compilation Tool ](https://msdn.microsoft.com/en-us/library/ms229863.aspx). – KiwiPiet Nov 09 '15 at 19:37
  • Do you have two copies of the DLL present on the server? It may be finding the same function in two separate dlls. – JosephStyons Nov 09 '15 at 19:38
  • 2
    Scratch that. I misread the method names – KiwiPiet Nov 09 '15 at 19:39
  • @xxbbcc - I actually do not see ANY files in the `Temp ASP` folder. I am running the project in the local IIS Express that fires up on my machine when hitting F5... does IIS E store them somewhere else than the usual path (`C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files`). I looked in both **Framework** and **Framework64**. – eidylon Nov 09 '15 at 19:43
  • @xxbbcc @JosephStyons - I did find two versions, ... apparently Local IIS Express stores its temporary asp files in a different location... `C:\Users\myuser\AppData\Local\Temp\Temporary ASP.NET Files` . Unfortunately deleting both of them and then letting the files be regenerated did not help. – eidylon Nov 09 '15 at 19:51
  • It's totally awesome when asp.net does weird stuff like this. The answer may be something as stupid as rebooting. –  Nov 09 '15 at 19:58
  • @eidylon If you're _absolutely sure_ that your function is not declared more than once than your problem is definitely a rogue copy of your DLL that contains that function. I'd clean up all temp files (for IIS Express, the framework and the Windows Temp folder), all build folders and restart the machine. – xxbbcc Nov 09 '15 at 19:58
  • 2
    Try deleting your bin and obj folders, then rebuild. Clean sometimes isn't enough. – hatchet - done with SOverflow Nov 09 '15 at 20:00

1 Answers1

0

Apparently this has to do with the App_Code folder.

It would seem that anything in the App_Code folder gets both compiled into the DLL, AND left there and compiled at run-time. Thus there were two copies of the class loaded into the same namespace at run-time, hence the error.

I moved all of the files which were in App_Code to a new, non-ASP.NET-special-folder, and now that error goes away.

eidylon
  • 7,068
  • 20
  • 75
  • 118
  • Old answer but I had the same issue with a different fix. Check the references for the project. For me the issue was somehow after importing a nuget package the references were updated to contain a reference to the project itself. I deleted that reference and the errors went away. – user3352617 Jan 30 '19 at 11:25