3

I have a parent IIS application that uses ELMAH and a child ASP.NET application (virtual directory) that doesn't use ELMAH. When I try to browse my subapplication I get this error:

Could not load file or assembly 'Elmah' or one of its dependencies. The system cannot find the file specified.

Which is understandable as my child application's bin folder doesn't contain any ELMAH assemblies.

The problem probably is that the parent web.config file contains this:

  <configSections>      
    <sectionGroup name="elmah">
      <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
      <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
      <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
      <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
    </sectionGroup>
  </configSections>

As far as I understand there is no way to stop <configSections> inheritance, see e.g. How to stop inheritance of <configSections>in Web.Config. Is there a way to run my ELMAH-free subapplication then?

Community
  • 1
  • 1
Borek Bernard
  • 50,745
  • 59
  • 165
  • 240

2 Answers2

0

You cannot keep your subapplication ELMAH-free because of the parent configuration. However - since I imagine you don't want to reference the assemblies from the parent - what you can do is tell your subapplication to look for assemblies in the parent bin folder with the probing configuration.

This way your subapplication doesn't need to know what assemblies exist for the parent, only that if an unknown assembly is needed it can be found in the parent folders


Edit: That's indeed a bummer. Clearing and removing configsections tags was considered too complex by Microsoft :

<clear /> and <remove /> were never implemented for configSections and sectionGroups because of the difficulty involved attempting to merge different definitions of the same section-handlers and section groups.

Hence the path workaround. You could also set up the applications so they are not related in terms of hierarchy, if this is critical

samy
  • 14,832
  • 2
  • 54
  • 82
  • "You cannot keep your subapplication ELMAH-free because of the parent configuration." Really? That would be a bummer, those two apps have nothing in common and shouldn't inherit anything from each other. – Borek Bernard Sep 02 '14 at 12:08
  • Can you please expand on your last line? What would be the workaround? Thanks. – Borek Bernard Sep 02 '14 at 13:56
  • If you add to your subapplication a probing path to the parent application bin folder, the application will be able to find any assembly the parent needs without referencing it. See link in answer – samy Sep 02 '14 at 14:02
  • @samy The probing path `Specifies subdirectories of the application's base directory that might contain assemblies.` So how do you add a probing path the parent application bin folder, the parent application is unlikely to be a sub directory of the sub application. Have I misunderstood? – philreed May 07 '15 at 13:47
0

I have found that adding enableConfigurationOverride="false" to the application pool definition fixes this problem.

From the MSDN docs:

Optional Boolean attribute. When true, indicates that delegated settings in Web.config files will processed for applications within this application pool. When false, all settings in Web.config files will be ignored for this application pool.The default value is true.

There are two methods of doing this, where ChildApplicationName should be replaced with the value of your application pool name.

Method 1 (preferred/advised):

Execute the following command in appcmd in Administrator mode:

appcmd.exe set config -section:system.applicationHost/applicationPools /[name='ChildApplicationName'].enableConfigurationOverride:"False" /commit:apphost

Method 2:

The second involves directly editing the %windir%\System32\inetsrv\config\applicationHost.config file allows the application to effectively ignore the parent application. For various reasons, I don't advice doing this, but I leave this here for posterity.

In order to set this, do a search for your child application pool name. It should be under the xpath. /configuration/system.applicationHost/applicationPools.

<configuration>
  <system.applicationHost>
    <applicationPools>
      ...
      <add name="ChildApplicationName" enableConfigurationOverride="false" />
      ...
    <applicationPools>
  <system.applicationHost>
<configuration>
Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114