I'm getting married! - More Details

ASP.NET 2.0 Mismatched Tag and aspnet_compiler

Thursday, December 21, 2006 12:37 PM

I spent most of the morning tracking down what appears to be a significant bug in the way Visual Studio 2005 compiles web sites.

The short of it: If you have mismatched ASP.NET tags in an ASPX file in a directory of your website, all subsequent directories will not be compiled. Your solution will show "Build Succeeded", even though there are syntax errors in those subsequent directories.

Here's an example...

Solution To begin, i have a fairly standard ASP.NET solution, containing a single web site (not a web project), and a class library. We're primarily focused on the web site...

You'll see that there are a number of directories, each containing an ASPX page. As you're probably aware, in ASP.NET 2.0, when you "build" the site, the ASP.NET compiler will compile each of these directories into their own assembly.

Directory1 contains a single, error-free aspx page.

Directory2 is where the problem code exists. It contains an ASP.NET tag which does not have a matching end tag. In this case, it's an asp:Hyperlink...

Directory3 has some more problem code, in this case, it's a nasty syntax error in the code behind file.

Directory4 contains ANOTHER mismatched tag, same as Directory1.

Now, one would expect a couple of things to happen when you "Build" the solution... First, the compiler should catch the mismatched tag and report it as an error. Second, the compiler should definately catch the C# syntax error in the code-behind, and report it as well.

Oddly enough, this is not the case... If I right-click the solution, and select "Rebuild Solution", here's what happens...

2 succeeded?!?! WTF!!!!

Visual Studio indeed reports that the build succeeded. Pay close attention though, it STOPPED BUILDING DIRECTORIES after Directory2.

After trying a number of things to get this working (compiling, cleaning solution, publishing, etc), I finally tried to compile the web site manually, using the aspnet_compiler tool.

At first try, it doesn't report any errors as well...

At this point I thought all was lost, until I discovered that the aspnet_compiler has a flag errorstack, which "Shows extra debuggin information that can help debug certain conditions." How ambiguous.

But, I tried it anyway...

Progress! Finally, I get an ERROR MESSAGE! A really helpful one at that

HttpParseException: Unexpected end of file looking for </asp:HyperLink> tag.

Now, armed with this information, I can fix the problem. Doing so, and rebuilding the solution reveils our sytax error!

Sucess! (Sort of)..

Final Thoughts

There's a couple of things to note:

  • It appears to be Directory Order specific. That is, it compiles the directories in order, and will blow up on the syntax errors if the mismatched tag is AFTER.
  • If you PUBLISH the website, the build will succeed, and the publish will succeed, but all of the files in the destination directory will have been removed, with no new ones in their place!

I still have no solution for my problem, short of compiling the website every time (or every so often) with aspnet_compiler and specifying the errorstack flag.

I've played around a bit with various settings in Visual Studio, but with no luck. I even tried this on another developers machine who had installed SP1, also with no luck.

If anyone has a suggestion, leave it in the comments!

Comments

David Ebbo
Hi Dusty,

This definitely is a bug in our error reporting logic. It appears to be very specific to unclosed tag errors. I can't think of a great workaround, other than the one you already found (using -errorstack).

I will forward this issue to the team.

thanks for reporting this!
David
Zink
Nice find!

Hopefully this helps some other developers out. Too bad it's a hard issue to really "search" for or even identify.
James
There are so many people on the web with the same prob, I am glad I landed on your blog, BTW if you need some decent asp.net hosting I would recommend redfoxhosting
Ken
Great article but I have a different issue. I can publish my website without any issues using the command line compiler but I fail with an "Index Out Of Bounds" exception whenever I attempt to publish the website within VS. I recently changed the default path to just / and I think that might be causing the issue - any ideas? Thanks!
manny
for the longest time I thought I was the only one with this problem. Thank you soooo much for showing how to debug this issue!
CuongLuc
You really rock, Dusty!!

I've been struggling with publishing my website for days before I saw your solution. Visual Studio 2005 has a lot of bugs, I can't understand why it could ignore validation error and just said "publish succeeded" but no file generated. M$ developers even don't post any article about this on the MSDN.

Finally, thank you very much Dusty. Keep going on :)
Greg Ratajik
Thank you VERY much for this - my publish was ending with "1 succeeded" - but nothing was happening. Everything was working yesterday, so I had no idea what was up. Turns out a had a type-o in a " tag. I'm rather shocked (and annoyed!) that this was preventing a publish, without any kind of error or warning.

Guess I need to hand-compile now.

BTW, How did you (or did you) get the switch on the compile from inside studio? I didn't see a option for that.

Thanks!
-Greg

Cannot publish
Hi all,

I have a solution with 5 class library projects and a web site that
has references to these projects.
The problem is, when I build the web site and browse through the
pages, there is no problem.

But when I try to publish the web site, errors come up that say ie.
"ABC does not contain a definition for DEF()". The weird part is,
there is a method DEF() in class ABC and it works when I build and
browse.
What is more weirder is that when I select the fixed naming option
during publish, there is no problem.
I do not wish to select this type of compilation because of
performance issues.
I have tried the aspnet_compiler with -errostack parameter and got the same error message.

Please help...

--Yigit
Margaret
I think this hotfix may help

"FIX: A Web site is not published when you try to publish the site by clicking "Publish Web Site" on the "Build" menu in Visual Studio 2005"

http://support.microsoft.com/kb/933608/en-us

Anjali
Hi Dusty,
This post has been very helpful to me! Thanks a lot.
Though errorstack gives me a mismatched tag but it doesnt tell me which file this tag is in.
Could you please tell me what would be the way to figure that out?
Thanks!
Anj
Aaron
Funny, I am encountering the same thing ... I'm using the web-deployment projects thingamajig, and it tells me end of file when looking for asp:Label tag. Thankfully, I only have 300 aspx pages and about 15000 labels. But I'm'onna getcha!
Monty
You really rock!!! I have wasted 5 hours of my billable time over this
Vinod MS
Hi all, I also encountered same problem. I searched and found this:
http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=97450
And there is no fix for it till now.
All we can do is to compile it manually from commandline using -errorstack switch.

So I have 2 options:
1: Build a wrapper exe to replace and run aspnet_compiler.exe with -errorstack option always. You have to redirect standard output/error from original exe.
2: Get the sourcecode of aspnet_compiler.exe and build your own version with detailed error informations,filenames,line-number,etc.

--MSV
retrytuyiu
qfretrnpn


Post a comment

   
 
  
  

    

All content © Dusty Davidson