Nested configuration and unity extensions

Jun 24, 2009 at 5:39 PM
Edited Jun 24, 2009 at 5:41 PM

 

Some background: I'm using CWAB to implement Modularity.  I'm following CWAB's example on how each module has it's own configuration file.  I've upgraded CWAB to leverage Unity as the container.  For the most part, this all works fine.  I have unity configuration sections in both the web.config and the module's config that specify type aliases and mappings and everything works fine. As shown below:

/Web.config

 <unity>

    <typeAliases>

      blah blah blah

    </typeAliases>

    <containers>

      <container>

        <types>

          blah blah blah

        </types>     

     </container>

    </containers>

  </unity>

 

/MyModule/web.config

<unity>
    <typeAliases>
      blah blah blah
    </typeAliases>
    <containers>
      <container name=”MyModule”>
        <types>
          blah blah blah
        </types> 

      </container>
    </containers>
  </unity>

 

My root container is configured using the unity section in the root web.config.  A child container is created and configured using the unity config in the MyModule/web.config. 

The Problem: I want to use Unity Interception.  When I add the corresponding extension, everything runs fine.  But when I add an interceptor target configuration element, I get a configuration error when trying to configure the container.  So when i do this:

/Web.config

 <unity>

    <typeAliases>

      blah blah blah

    </typeAliases>

    <containers>

      <container>

        <types>

          blah blah blah

        </types>     

      <extensions>

          <add type="Microsoft.Practices.Unity.InterceptionExtension.Interception, Microsoft.Practices.Unity.Interception" />

        </extensions>

        <extensionConfig>    

          <add name="interception" type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationElement, Microsoft.Practices.Unity.Interception.Configuration">

            <interceptors>

              <interceptor type="Microsoft.Practices.Unity.InterceptionExtension.VirtualMethodInterceptor, Microsoft.Practices.Unity.Interception">

                      <key type=”mytype” name=”typename”/>

              </interceptor>

            </interceptors>

          </add>

        </extensionConfig>

     </container>

    </containers>

  </unity>

 

/MyModule/web.config

<unity>
    <typeAliases>
      blah blah blah
    </typeAliases>
    <containers>
      <container name=”MyModule”>
        <types>
          blah blah blah
        </types> 

      </container>
    </containers>
  </unity>

 

I get the following error.  Note how the source file is the module’s web.config even though I get the exception when trying to configure the root container using the unity section in the root web.config:

Server Error in '/REBARTestApp' Application.


Configuration Error

Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error details below and modify your configuration file appropriately.

Parser Error Message: An error occurred creating the configuration section handler for unity: Operation is not valid due to the current state of the object.

Source Error:

 

Line 34:         </authorization>

Line 35:   </compositeWeb>

Line 36:   <unity>

Line 37:     <containers>

Line 38:       <container name="TestBizMod">


Source File: c:\Projects\REBAR\REBAR\Main\Accenture.REBAR.TestApp\WebSites\REBARTestApp\testbizmod\web.config    Line: 36


Version Information: Microsoft .NET Framework Version:2.0.50727.3053; ASP.NET Version:2.0.50727.3053

 

 

The full exception information is below:

 

System.Configuration.ConfigurationErrorsException occurred

  BareMessage="An error occurred creating the configuration section handler for unity: Operation is not valid due to the current state of the object."

  Filename="c:\Projects\REBAR\REBAR\Main\Accenture.REBAR.TestApp\WebSites\REBARTestApp\testbizmod\web.config"

  Line=36

  Message="An error occurred creating the configuration section handler for unity: Operation is not valid due to the current state of the object. (c:\Projects\REBAR\REBAR\Main\Accenture.REBAR.TestApp\WebSites\REBARTestApp\testbizmod\web.config line 36)"

  Source="System.Configuration"

  StackTrace:

       at System.Configuration.BaseConfigurationRecord.EvaluateOne(String[] keys, SectionInput input, Boolean isTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult)

       at System.Configuration.BaseConfigurationRecord.Evaluate(FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentResult, Boolean getLkg, Boolean getRuntimeObject, Object& result, Object& resultRuntimeObject)

       at System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)

       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey, Boolean getLkg, Boolean checkPermission)

       at System.Configuration.BaseConfigurationRecord.GetSection(String configKey)

       at System.Web.HttpContext.GetSection(String sectionName)

       at System.Web.Configuration.HttpConfigurationSystem.GetSection(String sectionName)

       at System.Web.Configuration.HttpConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection(String configKey)

       at System.Configuration.ConfigurationManager.GetSection(String sectionName)

       at Accenture.REBAR.EAC.Containers.UnityCompositionContainer.GetUnityConfigSection() in c:\projects\REBAR\REBAR\Main\Accenture.REBAR.EAC\Accenture.REBAR.EAC\Containers\UnityCompositionContainer.vb:line 79

  InnerException: System.InvalidOperationException

       Message="Operation is not valid due to the current state of the object."

       Source="Microsoft.Practices.Unity.Interception.Configuration"

       StackTrace:

            at Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptorTargetConfigurationElementCollection.CreateNewElement()

            at System.Configuration.ConfigurationElementCollection.CreateNewElement(String elementName)

            at System.Configuration.ConfigurationElementCollection.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElement.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElementCollection.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElement.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElementCollection.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElement.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElementCollection.Reset(ConfigurationElement parentElement)

            at System.Configuration.ConfigurationElement.Reset(ConfigurationElement parentElement)

            at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionImpl(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

            at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSectionWithRestrictedPermissions(RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

            at System.Configuration.RuntimeConfigurationRecord.RuntimeConfigurationFactory.CreateSection(Boolean inputIsTrusted, RuntimeConfigurationRecord configRecord, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

            at System.Configuration.RuntimeConfigurationRecord.CreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader)

            at System.Configuration.BaseConfigurationRecord.CallCreateSection(Boolean inputIsTrusted, FactoryRecord factoryRecord, SectionRecord sectionRecord, Object parentConfig, ConfigXmlReader reader, String filename, Int32 line)

       InnerException:

 

 

Any ideas???

Jun 24, 2009 at 7:25 PM

Update:  I found where the exception is being thrown explicitly in the Unity.Interception.Configuration assembly.  I still can't explain why.  I am continuing to debug. 

 

/// Collection of <see cref="InterceptorTargetConfigurationElementBase"/> elements
    /// from the configuration file.
    /// </summary>
    /// <seealso cref="InterceptorTargetConfigurationElementBase"/>
    /// <seealso cref="KeyInterceptorTargetConfigurationElement"/>
    /// <seealso cref="DefaultInterceptorTargetConfigurationElement"/>
    // FxCop suppression: This is not a normal collection, not going to implement generic interfaces
    [SuppressMessage("Microsoft.Design", "CA1010:CollectionsShouldImplementGenericInterface")]
    public class InterceptorTargetConfigurationElementCollection : TypeResolvingConfigurationElementCollection
    {
        ///<summary>
        ///When overridden in a derived class, creates a new <see cref="T:System.Configuration.ConfigurationElement"></see>.
        ///</summary>
        ///<returns>
        ///A new <see cref="T:System.Configuration.ConfigurationElement"></see>.
        ///</returns>
        protected override ConfigurationElement CreateNewElement()
        {
            throw new InvalidOperationException();
        }