Interception Configuration

Mar 16, 2010 at 3:26 PM
Edited Mar 16, 2010 at 3:43 PM

Hi, I'm using Unity 1.2 and .NET 4.0, and trying to set up a configuration file for unity interception. I'm getting the following error when calling ConfigurationManager.GetSection("unity"):

{"Value cannot be null.\r\nParameter name: type"}    System.Exception {System.ArgumentNullException}

After doing some troubleshooting I've narrowed it down to the extensionConfig configuration section in my unity configuration. If I comment out the extensionConfig section, Unity loads fine and I can resolve specified types. Here's my unity configuration:

 

<unity>
  <typeAliases>
    <typeAlias alias="interface" type="Microsoft.Practices.Unity.InterceptionExtension.InterfaceInterceptor, Microsoft.Practices.Unity.Interception, Version=1.2.0.0" />

    <!-- Attributes -->
    <typeAlias alias="Revisioned" type="Project.BusinessService.Concurrency.Revisioned, Project.BusinessService" />
    <typeAlias alias="RevisionedHandler" type="Project.BusinessService.Concurrency.RevisionedHandler, Project.BusinessService"  />
      
    <!-- Interfaces -->
    <typeAlias alias="IComplaintDAO" type="Project.DAO.Contract.IComplaintDAO, Project.DAO" />
    <typeAlias alias="IComplaintService" type="Project.BusinessService.Contract.IComplaintService, Project.BusinessService" />
    <typeAlias alias="INHibernateSessionManager" type="Project.DAO.Contract.INHibernateSessionManager, Project.DAO" />
      
    <!-- Implementations -->
    <typeAlias alias="ComplaintDAO" type="Project.DAO.DAO.ComplaintDAO, Project.DAO" />
    <typeAlias alias="ComplaintService" type="Project.BusinessService.Service.ComplaintService, Project.BusinessService" />
    <typeAlias alias="NHibernateSessionManager" type="Project.DAO.DAO.NHibernateSessionManager, Project.DAO" />
  </typeAliases>
  <containers>
    <container>
      <types>
        <type type="IComplaintDAO" mapTo="ComplaintDAO" />
        <type type="IComplaintService" mapTo="ComplaintService" />
	<type type="INHibernateSessionManager" mapTo="NHibernateSessionManager" />
      </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="interface">
              <default type="IComplaintService"/>
            </interceptor>
          </interceptors>
        </add>
      </extensionConfig>
    </container>
  </containers>
</unity>

I've made sure that I have references to the specified assemblies in my project (My project assemblies, the 4 unity assemblies, and ObjectBuilder2). Does anyone see what I'm doing wrong? Thanks.

 

 

Mar 16, 2010 at 6:50 PM

I discovered what I was doing wrong. In my class where I'm calling `ConfigurationManager.GetSection("unity")`, I needed to import "Microsoft.Practices.Unity.InterceptionExtension".

It seems kind of odd that I'd need to do that for the GetSection call. It might be an artifact of me using the .NET 4.0 RC.

 

Mar 16, 2010 at 6:52 PM

try to use assemblyqualifiedname for type register like below

<add type="Microsoft.Practices.Unity.InterceptionExtension.Interception, Microsoft.Practices.Unity.Interception, Version=1.2.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />

i am trying the samething you mentioned here, but my problem is after i use assemblyqualifiedname, i got exception saying "Unrecognized element 'interceptors'", did you have clue?

Mar 16, 2010 at 7:05 PM

dkonline, we posted at the same time. Did you see my fix?

 

Mar 16, 2010 at 8:03 PM
Thanks wfuqua, I meant by adding assemblyqualifiedname might solve your problem, I encountered the same thing before, while my problem now is "Unrecognized element 'interaceptors".
Mar 16, 2010 at 8:06 PM

please ignore my previous post, i somehow put the section out of <add> note. it is running now. thanks.