Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#编译器函数本身不明确_C#_Function_Ambiguous_Ambiguous Call - Fatal编程技术网

C#编译器函数本身不明确

C#编译器函数本身不明确,c#,function,ambiguous,ambiguous-call,C#,Function,Ambiguous,Ambiguous Call,在我继承的一个C#WebApp项目中工作。我有几个函数定义,所以 public static DataTable ExecuteDT(this AppDBContext target, string sql, int timeoutSeconds = defaultTimeoutSeconds) { DbCommand cmd = target.Database.Connection.CreateCommand(); cmd.CommandText = sql; cmd.

在我继承的一个C#WebApp项目中工作。我有几个函数定义,所以

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];
}
当我在应用程序上进行构建时,它编译得很好,没有错误。
但是,当我尝试运行网站(使用F5)时,它会在我的浏览器中启动,然后出现编译错误:

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 
它抱怨同一个确切的函数本身不明确。我已经搜索了所有的源代码,这是这个函数的一个也是唯一的声明,所以我真的很想知道编译器对什么感到困惑

我在谷歌上发现的唯一一个与此类似的问题是,某个人的项目以某种方式结束了对自身的引用。我仔细检查了一下,以确保这个项目没有引用自身,也没有

我还尝试过对项目进行清理和重建

不管出于什么原因,这个项目在IDE中编译得很好,但是当试图在浏览器中运行它时,它就失败了


我在VS 2015中工作,目标是框架的4.5.2版本。

显然这与
App\u code
文件夹有关

似乎
App\u code
文件夹中的任何内容都会被编译到DLL中,然后留在那里并在运行时编译。因此,在运行时有两个类的副本加载到同一名称空间中,因此出现了错误


我将
App\u code
中的所有文件移动到一个新的非ASP.NET专用文件夹中,现在错误消失了。

您是否尝试删除
临时ASP.NET文件的内容
?有时,以前版本的DLL会卡在那里,并且在编译器执行magic时会干扰一组较新的二进制文件。仅供参考:中的源文件。'您可以将源代码存储在App_code文件夹中,它将在运行时自动编译。“。您可以使用[ASP.NET编译工具]()预编译这些文件。服务器上是否有两个DLL副本?可能是在两个单独的DLL中找到相同的函数。请擦掉它。我误读了方法名称尝试删除您的bin和obj文件夹,然后重建。清洁有时是不够的。旧的答案,但我有一个不同的修复相同的问题。检查项目的参考资料。对我来说,问题是在导入nuget包之后,引用被更新为包含对项目本身的引用。我删除了那个引用,错误就消失了。