C# ASP.NET 运行时错误:找到不明确的匹配
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1323865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET runtime error : Ambiguous Match found
提问by natch3z
Recently, my team converted ASP.NET project from .NET 1.1 to .NET 2.0. Everything is pretty good so far except for one web page.
最近,我的团队将 ASP.NET 项目从 .NET 1.1 转换为 .NET 2.0。到目前为止,除了一个网页外,一切都很好。
This is the error message I got when I tried to open this page:
这是我尝试打开此页面时收到的错误消息:
Server Error in '/' Application.
Parser Error Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: Ambiguous match found.
Source Error:
Line 1: <%@ Control Language="c#" AutoEventWireup="false" Codebehind="Template.ascx.cs" Inherits="eReq.Web.WebControls.Template.Template" TargetSchema="http://schemas.microsoft.com/intellisense/ie5" %> Line 2: Line 3: function ExpandCollapse_Template(inBtn, inSection, inSectionID) {
Source File: /WebControls/Template/Template.ascx
Line: 1-------------------------------------------------------------------------------- Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053
“/”应用程序中的服务器错误。
解析器错误说明:解析服务此请求所需的资源期间发生错误。请查看以下特定解析错误详细信息并适当修改您的源文件。
解析器错误消息:找到不明确的匹配。
源错误:
第 1 行:<%@ Control Language="c#" AutoEventWireup="false" Codebehind="Template.ascx.cs" Inherits="eReq.Web.WebControls.Template.Template" TargetSchema="http://schemas.microsoft. com/intellisense/ie5" %> 第 2 行:第 3 行:函数 ExpandCollapse_Template(inBtn, inSection, inSectionID) {
源文件:/WebControls/Template/Template.ascx
行:1-------------------------------------------------- ------------------------------ 版本信息:Microsoft .NET Framework 版本:2.0.50727.3053;ASP.NET 版本:2.0.50727.3053
I tried renaming class and renaming filename but it didn't work.
我尝试重命名类和重命名文件名,但没有用。
Anyone have any idea on this?
有人对此有任何想法吗?
采纳答案by x2.
It may appeared because of different names of components? for example Button1 and button1, it compiles as casesensitive, but executed as caseinsensitive.
它可能是因为组件名称不同而出现的?例如 Button1 和 button1,它编译时区分大小写,但执行时不区分大小写。
回答by x2.
In your ASCX file, go through each and every control and change its id. For example,
在您的 ASCX 文件中,检查每个控件并更改其 ID。例如,
<asp:TextBox id="foo" />
change it to
将其更改为
<asp:TextBox id="foo1" >
You've probably got a control with an ID that matches a property in your ascx file, so when the compiler is trying to make instance variables its colliding.
您可能有一个 ID 与 ascx 文件中的属性匹配的控件,因此当编译器尝试使其实例变量发生冲突时。
回答by Daniel Elliott
I'd trawl your web.config for 1.1 and 2.0 references to the same DLL. In most cases that I have gotten this it was System.Web.Extensions.
我会在你的 web.config 中搜索 1.1 和 2.0 对同一个 DLL 的引用。在大多数情况下,我得到的是 System.Web.Extensions。
Also check the @registers in Pages if that fails.
如果失败,还要检查页面中的@registers。
Good luck (it is not a fun bug to find!)
祝你好运(这不是一个有趣的错误!)
Dan
担
回答by Nariman
This is due to what can only be described as a defect in System.Web.UI.Util.GetNonPrivateFieldType(Type classType, String fieldName)that allows UI (.aspx/.ascx) fields to compile as case-insensitive but attempts to retrieve them as case-sensitive during the intial parse.
这是因为System.Web.UI.Util.GetNonPrivateFieldType(Type classType, String fieldName)中的一个缺陷,它允许 UI (.aspx/.ascx) 字段编译为不区分大小写但尝试检索它们在初始解析期间区分大小写。
A potential remedy for the time being is to catch it at compile-time with an ms-build task.
目前一个潜在的补救措施是在编译时使用ms-build task捕获它。
回答by Abdul Aziz Kasem
I've the same problem and it solved and the solution is in check your code behind and you will find a couple of Controls with the same name:
我有同样的问题,它解决了,解决方案是检查你的代码,你会发现几个同名的控件:
protected Button Home;
protected System.Web.UI.HtmlControls.HtmlAnchor home;
you have to erase one line or comment it.
您必须删除一行或对其进行注释。
回答by SoliQuiD
The selected answer seems to be the right one.
所选答案似乎是正确的。
In my case i found that im using a variable in the codebehind with the same name as a control in the aspx file, just with different case usage.
就我而言,我发现我在代码隐藏中使用了一个与 aspx 文件中的控件同名的变量,只是大小写不同。