Interception Configuration

Mar 16, 2010 at 2:26 PM
Edited Mar 16, 2010 at 2: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:


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

    <!-- 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" />
        <type type="IComplaintDAO" mapTo="ComplaintDAO" />
        <type type="IComplaintService" mapTo="ComplaintService" />
	<type type="INHibernateSessionManager" mapTo="NHibernateSessionManager" />
        <add type="Microsoft.Practices.Unity.InterceptionExtension.Interception, Microsoft.Practices.Unity.Interception" />
        <add name="interception" type="Microsoft.Practices.Unity.InterceptionExtension.Configuration.InterceptionConfigurationElement, Microsoft.Practices.Unity.Interception.Configuration">
            <interceptor type="interface">
              <default type="IComplaintService"/>

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 5: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 5:52 PM

try to use assemblyqualifiedname for type register like below

<add type="Microsoft.Practices.Unity.InterceptionExtension.Interception, Microsoft.Practices.Unity.Interception, Version=, 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 6:05 PM

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


Mar 16, 2010 at 7: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 7:06 PM

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