Wednesday, August 10, 2011

APP_CODE: Order of install matters

Today I installed some code on an existing asp.net website. It required copying code into the APP_CODE folder. This is an ASP.NET "magic" folder.  Any code placed in this folder is auto-magically compiled to a dll and the code is made available globally.

If all the code you place in this folder is written in the same language, it works, but what if you are mixing csharp with vb?  With 1 language, ASP.NET can figure out what language you used and call the appropriate compiler for that language.  With more than 1 language, ASP.NET will start throwing errors about mixing languages and that it cannot compile a VB program with a CSharp compiler (or something like that).

You CAN mix languages, But you must help ASP.NET figure out how to separate the code so that it knows how to logically separate the code into separate DLLs.  You do this by placing the code in separate folders and use the codeSubDirectories tag in web.config to tell ASP.NET to treat the folders as separate code bases (assemblies/DLLs).

OK...  So that's important to know, but that information is readily available on the net via Google.  So what is my post about?  The order of operations: MODIFY web.config BEFORE adding your code sub-directory!

I installed a C# code folder into APP_CODE before I added the entry into the web.config.  What happened was that the production environment shutdown.  As soon as the folder was copied, ASP.NET began trying to re-compile the DLLs.  Because there was no "codeSubDirectories" entry for the new folder, ASP.NET tried compiling the CSharp code with the existing VB code and threw errors in the Server log that this was not ok.  Meanwhile, the website was throwing errors back to the public saying "Server Error".  This caused out website monitoring tools to go haywire.

This chaos continued for about 10 minutes until the web.config file had been modified.

No comments:

Post a Comment