Wednesday, December 28, 2011

Ambiguous match found - VS2003 to VS2005/VS2010 conversion mystery resolved!!

So I converted from vs2003 to VS2005 (as well as VS2010) and got this infamous 'Ambiguous match found error'!

The error message clearly pointed to the first user control registered in my web page. So the problem should be with that user control!
I tried to solve it for a couple of hours -> failed -> googled/binged.
1) Some people said remove the control/ user control declarion from code behind because vs2005 automatically adds the user control.
but if I remove the declaration then how can I use the control in code ( I get compile time error)

2) Some users said they had declared the control two times in the code behind page (same name with different case)
and I searched every where for the second declaration but could not find any.

3) Another bunch of users found the control re-declared in designer.cs
but I could not create/find this designer.cs !!
mine was a class library (with .ascx pages) hence I dont get the convert to web application option (when right clicking project/ascx-page). There were tweaks to change class library to webapplication so that I get the option(convert to web application) but did not work for me.

now what!!
well, I did the good old method of commenting all the html and uncommenting section by section to see where it fails.(only in the .ascx , did not touch the code behind)

Surprisingly I found the page working with the erroneous control(in the first error message) still present but some other parts of the page commented. That was when I realized the truth, .Net was bluffing me! and pointing me towards the wrong user control!
I slowly uncommented line by line and pin pointed error:-
  protected RequiredFieldValidator rfvDateCheck;
  protected RequiredFieldValidator RfvDateCheck;
Bingo!!
one random control was declared twice but not the one shown by the .net error message!
So what people were telling on blogs and forums were correct but just that I was searching for the wrong control!




No comments:

Post a Comment