Friday, November 10, 2006

ASP.NET 2.0: Ambiguous match exception

Just ran into an ambiguous match exception which seemed to appear out of nowhere. A perfectly good ASP.NET 1.1 website starts throwing the 'Ambiguous Match Exception' when switched to ASP.NEt 2.0. I didn't recompile, or anything. To complicate things a bit, the Ambiguous match exception doesn't state why it is occuring. I guess Microsoft decided to pay tribute to the exception's name ;) Anyways, I figured it out using various blogs. ASP.NET 2.0 uses partial classes, where ASP.NET 1.x uses plain classes. 2.0 will automatically declare all named controls (controls that have an ID) as members of the final class. If a control ID overlaps with a (protected) member already declared in the class the exception occures. Note that this issue doesn't seem to occur using the ASP.NET development server. Check out these links for more info: Peter Johnson's Blog: Ambiguous match found. Advanced .NET Debugging: "Ambiguous match found" in a Web Control - a Possible Bug

No comments: