Have you ever been left scratching your head after getting an error like this:
Parser Error Message: Could not load file or assembly 'MyUnrequiredAssembly' or one of its dependencies. The system cannot find the file specified. (C:\Inetpub\wwwroot\child\web.config line 89)
It’s common to have child sub-applications under the root application in an ASP.NET web site. It’s also common to have inheritance problems in a child because of what’s in the root application’s web.config file. To stop the child application from throwing a configuration error, you’ll often find that the previous developer has added assemblies to the GAC, or to every child application’s /bin folder in addition to the root folder’s /bin. You’ll also see similar stop-gap fixes with other resources, particularly in the App_Theme folder. Fortunately, if you are running at least .NET 2.0, or better, there’s a number of ways to fix things that won't throw the next guy working on the site for a loop.
The simplest way to handle this is to:
1. Remove the offending assembly in the system.web section of the child application's web.config file.
<remove assembly="MyUnrequiredAssembly" />
If you can't seem to get rid of the offending assembly, check for httpModules:
<remove name="MyUnrequiredAssembly" />
Sometimes, it is easier to start the child application with a clean slate. In that case:
2. Clear all the assemblies in the system.web section of the child application's web.config file.
<!-- Add required assemblies here -->
You can then go ahead and add the assemblies that the child application needs.
To take a different approach, you can also disable child inheritance in the root application:
3. Wrap the system.web settings of the root application web.config file in a location tag.
<location path="." inheritInChildApplications="false">
Finally, you can apply specific resources to child applications in the root web.config by using the 'path' attribute:
<!-- Configuration that applies to all applications -->
<!-- Configuration for the "ChildApp1" application. -->
<!-- Configuration for the child of child application "ChildApp1/App2" application. -->
Sciosoft Systems is a Canadian web design & development company based in Muskoka,
which is in central Ontario. We provide ASP.NET website & Windows Server application
development services to small and medium-sized business, as well as local government
and not-for-profit groups. If you have a website project you’d like to discuss,
please visit us at www.sciosoft.com.