Tuesday, April 7, 2009

aspnet_compiler and its mysterious silent failures

Around the year 2000, Microsoft started actually doing some things extremely well.

Internet Explorer 4 was the most abysmal web browser ever to disgrace the human race, but Internet Explorer 5 was remarkably solid.

Windows ME was their buggiest and single worst desktop operating system ever, but Windows 2000 was impressive.

Visual Basic 6, ASP, VBA, COM and all that stuff was a bit same-old, same-old - a clunky development experience. But the .NET framework truly ushered in a new era of programming productivity.

The .NET framework itself is awesome. Microsoft has never produced anything better, in my opinion, than the .NET framework.

But within the .NET framework lives an incredibly buggy tool called aspnet_compiler.

Unfortunately, some of us are forced to rely upon it.

It frequently fails with no error message.

Nada on the console.

Nada in the event log.

Just absolute silence.

It pretends it has happily successfully finished, but in actual fact, something has gone wrong and it absolutely refuses to tell you about it.

And that wastes hours. And hours. And did I mention, hours.

Today I lost about an hour and a half. Aspnet_compiler would succeed if I excluded any one of my dozen or so subfolders in my web root folder. But if I tried to include all my subfolders, it would grind away as if it was working successfully, and then it would suddenly fail without any error message.

I got it to the point that I could compile successfully if I excluded any one of several files in one particular folder, but if I tried to include them all, it would fail with no error message.

But if I removed a different subfolder from the root folder, I could include all those files that previously I could include all-but-one of.

It was aspnet_compiler demonstrating its classic fickleness. I think Microsoft invented it for no other purpose than to waste developers' time. OK, maybe that's getting a little too harsh...

Anyhow, lo-and-behold, when I copied the entire problematic precompilation-input folder to another location and tried again, it failed, but this time with a compilation error message that at least I can do something about.

What was the problem?

It seems that aspnet_compiler is unable to cope with long file paths. It seems that once the absolute file path to any file in the precompilation input exceeds some threshhold, aspnet_compiler becomes very fragile, and sometimes succeeds, but with slightly different input, sometimes fails.

By copying my source code to a temporary folder near the root of my drive, I shortened the maximum file path, and thus avoided aspnet_compiler's file-path-length issues.

But that's not the only stupid thing aspnet_compiler is known to do.

For example, sure, at least I'm getting a compilation error now. But the compilation error I'm getting actually has nothing to do with any of the files which, if I exclude, it all compiles successfully. i.e. the thing its tripping over now is not a real issue. But at least it gives me something to focus more specifically on.

Such are the vagueries of life with aspnet_compiler.

But wait, there's more!

Suppose you have two ASPX files in the same namespace and with the same base class name, and suppose it works fine during testing in IIS before precompilation. All good and well, you'd think. And then you try to precompile. And aspnet_compiler dies saying nothing more than that it "failed with error code 1" (or is it 0? it's a while since I last had this problem, though I've had it too many times before). The cause? aspnet_compiler requires that all class names throughout the entire web app be unique within their respective namespaces. Fair enough. It's a reasonably intuitive rule now that you mention it. But I had to figure it out for myself. 'Coz aspnet_compiler doesn't tell you what's wrong in this instance - it just dies with that very obscure error message.

And so I regret that I ever bought Microsoft's hype that aspnet_compiler is now the best and recommended pathway to shipping websites. The tool is unstable, unreliable, and frequently complains about non-existent problems.

But aside from aspnet_compiler, I love the .NET framework. It's the best thing Microsoft has ever done.

2 comments:

Wiebe Tijsma said...

Amen.

I was googling to have another issue answered though, for some reason I can't get the aspnet_compiler to compile my webapplication starting at the 'root' (/) of the Default Website.

No error messages, but no compilation either :(

Unknown said...

Yep,

I have the same issue (loving the .NET framework and hating its compilers).