find a location for property in a new city

Wednesday, 7 April 2010

Could not load file or assembly 'MyHttpModules' or one of its dependencies. The system cannot find the file specified. Web.config inheritance

I made a new Virtual Application in my current IIS site to my brand new web application and I get this filthy error. So I'm thinking, "Of course you cannot load the file or assembly because it isn't in this web application but then I didn't ask you to." So where is it coming from? This is what is happening and how to solve it.

The "problem" is to do with web.config inheritance. Your new virtual application is still inheriting from the site's root web.config despite being physically separated and so it is finding this reference to a resource that doesn't exist in the new application.

Solution

Let me introduce a little known attribute of the location element in configuration files. It is called inheritInChildApplications, which can be set to false and will do what is says on the tin. Simply place them around the settings you do not want inherited by your child app. Unfortunately you can only use it in quite a blanket fashion, i.e. you can put it around <system.web> but if you think you're putting it around individual settings then you must be crazy!

So for my problem with a nonexistent HttpModule I will need to stop the system.web and system.webServer inheriting in my child app:
<location inheritInChildApplications="false">
  <system.web>
    <!-- various web things -->
  </system.web>
  <system.webServer>
    <!-- various web server things -->
  </system.webServer>
</location>

Unfortunately, this is so unknown that apparently not even Visual Studio knows about it so you can bask in the glory of your handy work with a squiggly blue line! (I think a squiggly blue line must indicate good code!)

Follow britishdev on Twitter

3 comments:

  1. Thanks, this has helped me out.

    ReplyDelete
  2. I killed my Sharepoint environment, but got it back. You pointed me in the right direction. I needed to set the Web application pools that where in use by SharePoint. To .NET 2.0 instead of 4.0.
    Thanks a lot!

    ReplyDelete
  3. I am facing this problem since few days and finally yet found the solution. Didn't thought that this can be a solution, quite a simple solution but still not known to many of us.

    ReplyDelete