Wednesday, February 08, 2006

Ambiguous match found error in precompiled ASP.NET page

I upgraded an ASP.NET 1.1 project to 2.0 and precompiled it before uploading it to my production web server. Unfortunately one of the pages refused to work (I thought pre-compilation was supposed to find these problems!).

This is the error I was getting when I viewed the problem page:-

Parser Error Message: Ambiguous match found.

It turns out that Visual Studio 2005 creates hidden field declarations for all controls inserted into a page. For some reason my old code had the following field declaration:-

18 namespace ITM

19 {

20 ///

21 /// Summary description for WebForm1.

22 ///

23 public partial class WebForm1 : System.Web.UI.Page

24 {

25 protected System.Web.UI.HtmlControls.HtmlInputFile file2;


Because my code had a declaration for file2 it clashed with the declaration that VS2005 has created. This results in a project that compiles without any problem but refuses to run!!! (The project woks fine in dynamic compilation mode)

This bug has already been reported to Microsoft as bug FDBK38831 but it is shown as "Won't Fix" because VS2005 cannot detect the error. It would be better if the error message was a little clearer!

If you have this problem make sure you do not declare any variables with the same name as any of your controls.

1 comment:

Andre said...

Aaah! Brilliant! Thanks for sharing man. This stupid error kept me busy the whole day.

The web app works fine on the dev machine, but not on the test server.