Samer Ibrahim's Blog

The Samer I Warrior on battles with .NET

Lists/Forums/Etc.

Which Blogs do I read?

Odd behavior in ASP.NET

So after wasting about an hour and a half debugging why in the world I kept getting an invalid cast exception, I discovered a quirk in the way ASP.NET loads assemblies.  Apparently, the .NET framework loads everything in the \bin directory that even looks like a DLL.  For example, if you have a file called DLL_ the framework will load it anyway.  Why the hell it does this I don't know!!!  It's not even a DLL for God's sake!

Now you might be wondering why in the world I have a file called DLL_ sitting in my \bin directory but that's easy to explain.  Sometimes I want to use a different compilation of a DLL that might contain something like more debugging code, for example, in my ASP.NET application.  So instead of moving or overwriting the old version or recompiling my application or even changing which version is redirected to what other version in the config file, I simply change the old DLL to DLL_ or something of the like and drop the new DLL in the \bin directory along side of it.  Seems harmless and should work and in fact it does when .NET isn't being stupid and just loads DLLs. 

I spent all this time trying to figure out this problem, changing the code I was debugging over and over again, and when I finally said what the hell let me see what the code base is for DLL which contains the class I'm trying to cast to, I saw that it was <Path>\SomeAssembly.DLL_.  This is a bug as far as I'm concerned.  And as far as I can tell, there is simply no application for this type of behavior so I'll just call it retarded.

By the way when I say ASP.NET, I'm working with SharePoint specifically.

Comments

Raymond Chen said:

If you do a "dir/x" you'll see that your file SomeAssembly.DLL_ has a short name of SOMEAS~1.DLL, so it is indeed a DLL after all.
# May 5, 2004 2:01 AM

Jon Galloway said:

Ah, Raymond's comment clears this up for me. I've never had that problem renaming the file to SomeAssembly.dll.bak, because that would be SOMEAS~1.BAK (not good to leave that way, because BAK files aren't protected from download).

We've had this problem before with our network admins, though - they back up a dll as "_SomeAssembly.dll" to simplify rollback.
# May 5, 2004 2:45 AM

Samer Ibrahim said:

Raymond,
While you are correct that indeed the underlying file structure is a DLL, that does not mean it should be loaded. Does that mean if I have a DLL and rename it to .TXT it will still load. I don't think so. I think this is a bug. Regardless of what kind of file structure is actually there, the loader should not load things that do not have the "DLL" extension. I highly doubt they pick up every file regardless of the extension and try to see if they can load it. If that was the case I'd see your point however I don't believe it is.
-Sam
# May 5, 2004 6:12 AM

Daniel Jin said:

Samer
but as raymond said, the short name (dos 8.3) does have DLL as it's file extension. so it is recognized as a DLL.

Jon
that can be easily solved by going into IIS, map .BAK extension to aspnet_isapi.dll, then in your web.config file, map the extension to System.Web.HttpForbiddenHandler. or you can do it in machine.config to set that for the whole server.
# May 5, 2004 8:39 AM

TrackBack said:

^_^,Pretty Good!
# April 10, 2005 6:35 AM

Odd behavior in ASP.NET said:

Pingback from  Odd behavior in ASP.NET

# November 28, 2007 2:05 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)