Ambiguous match found

I have had this exception a couple of times before and keep forgetting what the problem is and dedicating the best part of a morning figuring out what the problem is.
I had this issue today in a team development I was working on. Its a web application and when the new version was promoted to the UAT environment, it had and issue loading a particular page. The stack trace is below:
System.Reflection.AmbiguousMatchException: Ambiguous match found.
at System.RuntimeType.GetField(String name, BindingFlags bindingAttr)
at System.Web.UI.Util.GetNonPrivateFieldType(Type classType, String fieldName) at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildFieldDeclaration(ControlBuilder builder)
at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder, Boolean fInTemplate, Boolean topLevelControlInTemplate, PropertyEntry pse)
at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder, Boolean fInTemplate, Boolean topLevelControlInTemplate, PropertyEntry pse)
at System.Web.Compilation.BaseTemplateCodeDomTreeGenerator.BuildSourceDataTreeFromBuilder(ControlBuilder builder, Boolean fInTemplate, Boolean topLevelControlInTemplate, PropertyEntry pse)
at System.Web.Compilation.TemplateControlCodeDomTreeGenerator.BuildMiscClassMembers()
at System.Web.Compilation.BaseCodeDomTreeGenerator.BuildSourceDataTree()
at System.Web.Compilation.BaseTemplateBuildProvider.GenerateCode(AssemblyBuilder assemblyBuilder)
at System.Web.Compilation.AssemblyBuilder.AddBuildProvider(BuildProvider buildProvider)
 
The are a few pages on the internet whic give some basic explanation of the reasons behind this exception and the main one mentioned in the pages i have found if that people have had overloaded indexers on web controls. This is obviously a real cause for this issue but is not the only one.
The issue I keep having on team developements is caused by people deviating from our naming convention. The issue is caused by a type, normally a user control, having two (or more) public members with the same name (when considered case insensitive). This is an issue when the control/page is loaded as the loader uses reflection to find the public memebrs of the type. It does this with case insensitive options and can get errors if two things clash.
An Example of this is that we had an event on the control called something like DoTheBusiness. There was also a button on the control called doTheBusiness. This wasnt an issue in our C# app and caused no issues when running the webapplication through the visual studio web server. However, when loaded into an IIS environment it causes the issue shown in the stack trace.
It can be hard to track this down two as  the control you are loading the loading through LoadControl() or the page you are accessing might not have this issue. It could reference a control which has this issue or references one which does and so on.
Our naming conventions in our web applications and all the ones I have worked on is to use hungarian notation for the controls on the pages. this would prevent this issue as the button would(should)  not ever clash with public field on the page.
 
I hope this post helps people that experience this issue. Let me know if it helps you.
 
 
Advertisements
This entry was posted in Uncategorized and tagged , , . Bookmark the permalink.

2 Responses to Ambiguous match found

  1. Eric says:

    Hey thanks, your post gave me a few things to look into for resolving this strange error. My problem was like what you mentioned, I had a problem where the naming conventions for controls were not followed and conflicted with member variable names (even though one was CapsCase and one was camelCase.)
     
    Anyway thanks, the rest of google gave me nothing to go on.

  2. Andrey says:

    I had this exception after deployment website on server. Using provided idea I tried to find ambiguity in controls/methods/properties names on ASP page. But did not find. Only ranaming of all server controls on the page gave a result.Thank you.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s