Unity Configuration Error - Could not load type

Apr 22, 2009 at 3:30 PM
Edited Apr 22, 2009 at 4:01 PM
I am stuck. Any help would be appreciated. I recieve the following error

Could not load type 'IService`2' from assembly 'SEEDS.EntityContracts'.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.TypeLoadException: Could not load type 'IService`2' from assembly 'SEEDS.EntityContracts'.

Source Error:

Line 15:             UnityConfigurationSection config =
Line 16:                 ConfigurationManager.GetSection("unity") as UnityConfigurationSection;
Line 17: config.Containers.Default.Configure(IoC);

Here is my current configuration

  <unity>
    <typeAliases>
      <!-- LifetimeManager types -->
      <typeAlias alias="singleton" type="Microsoft.Practices.Unity.ContainerControlledLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="perThread" type="Microsoft.Practices.Unity.PerThreadLifetimeManager, Microsoft.Practices.Unity" />
      <typeAlias alias="external" type="Microsoft.Practices.Unity.ExternallyControlledLifetimeManager, Microsoft.Practices.Unity" />
      <!-- EntityContracts types -->
      <typeAlias alias="IService`2" type="SEEDS.EntityContracts.IService`2, SEEDS.EntityContracts" />
      <typeAlias alias="ITranslator`2" type="SEEDS.EntityContracts.ITranslator`2, SEEDS.EntityContracts" />
      <typeAlias alias="IErrorCollection" type="SEEDS.EntityContracts.IErrorCollection, SEEDS.EntityContracts" />
      <!-- CommonEntities types -->
      <typeAlias alias="ServiceLogEntry`2" type="SEEDS.EntityContracts.CommonEntities.ServiceLogEntry`2, SEEDS.EntityContracts" />
      <typeAlias alias="EntityReference" type="SEEDS.EntityContracts.CommonEntities.EntityReference, SEEDS.EntityContracts" />
      <!-- CommunicationServices.MessageContracts types -->
      <typeAlias alias="CS_GetSecurityTokenRequest" type="SEEDS.CommunicationServices.MessageContracts.GetSecurityTokenRequest, SEEDS.CommunicationServices.MessageContracts"/>
      <typeAlias alias="CS_GetSecurityTokenResponse" type="SEEDS.CommunicationServices.MessageContracts.GetSecurityTokenResponse, SEEDS.CommunicationServices.MessageContracts"/>
      <typeAlias alias="CS_SetOrderDetailsRequest" type="SEEDS.CommunicationServices.MessageContracts.SetOrderDetailsRequest, SEEDS.CommunicationServices.MessageContracts"/>
      <typeAlias alias="CS_SetOrderDetailsResponse" type="SEEDS.CommunicationServices.MessageContracts.SetOrderDetailsResponse, SEEDS.CommunicationServices.MessageContracts"/>
      <typeAlias alias="CS_SetInteractionDetailsRequest" type="SEEDS.CommunicationServices.MessageContracts.SetInteractionDetailsRequest, SEEDS.CommunicationServices.MessageContracts"/>
      <typeAlias alias="CS_SetInteractionDetailsResponse" type="SEEDS.CommunicationServices.MessageContracts.SetInteractionDetailsResponse, SEEDS.CommunicationServices.MessageContracts"/>
      <!-- CommunucationServices.DataContracts types -->
      <typeAlias alias="CS_ErrorCollection" type="SEEDS.CommunicationServices.DataContracts.ErrorCollection, SEEDS.CommunicationServices.DataContracts"/>
      <!-- BusinessServices types -->
      <typeAlias alias="BS_ServiceLogService`2" type="SEEDS.BusinessServices.ServiceLogService`2, SEEDS.BusinessServices"/>
      <typeAlias alias="BS_GetSecurityTokenService`2" type="SEEDS.BusinessServices.GetSecurityTokenService`2, SEEDS.BusinessServices"/>
      <typeAlias alias="BS_SetOrderDetailsService`2" type="SEEDS.BusinessServices.SetOrderDetailsService`2, SEEDS.BusinessServices"/>
      <typeAlias alias="BS_SetInteractionDetailsService`2" type="SEEDS.BusinessServices.SetInteractionDetailsService`2, SEEDS.BusinessServices"/>
      <!-- BusinessServices.Messages types -->
      <typeAlias alias="BS_GetSecurityTokenRequest" type="SEEDS.BusinessServices.Messages.GetSecurityTokenRequest, SEEDS.BusinessServices.Messages"/>
      <typeAlias alias="BS_GetSecurityTokenResponse" type="SEEDS.BusinessServices.Messages.GetSecurityTokenResponse, SEEDS.BusinessServices.Messages"/>
      <typeAlias alias="BS_SetOrderDetailsRequest" type="SEEDS.BusinessServices.Messages.SetOrderDetailsRequest, SEEDS.BusinessServices.Messages"/>
      <typeAlias alias="BS_SetOrderDetailsResponse" type="SEEDS.BusinessServices.Messages.SetOrderDetailsResponse, SEEDS.BusinessServices.Messages"/>
      <typeAlias alias="BS_SetInteractionDetailsRequest" type="SEEDS.BusinessServices.Messages.SetInteractionDetailsRequest, SEEDS.BusinessServices.Messages"/>
      <typeAlias alias="BS_SetInteractionDetailsResponse" type="SEEDS.BusinessServices.Messages.SetInteractionDetailsResponse, SEEDS.BusinessServices.Messages"/>
      <!-- DataServices.ServiceModel types -->
      <typeAlias alias="SM_Message" type="SEEDS.DataServices.ServiceEntityModel.Message, SEEDS.DataServices"/>
      <typeAlias alias="SM_EntityReference" type="SEEDS.DataServices.ServiceEntityModel.EntityReference, SEEDS.DataServices"/>
      <!-- Translators -->
      <typeAlias alias="ErrorCollectionTranslator" type="SEEDS.Translators.ErrorCollectionTranslator, SEEDS.Translators"/>
      <typeAlias alias="SeviceLogEntryTranslator`2" type="SEEDS.Translators.ServiceLogEntryTranslator`2, SEEDS.Translators"/>
      <typeAlias alias="GetSecurityTokenRequestTranslator" type="SEEDS.Translators.GetSecurityTokenRequestTranslator, SEEDS.Translators"/>
      <typeAlias alias="SetOrderDetailsRequestTranslator" type="SEEDS.Translators.SetOrderDetailsRequestTranslator, SEEDS.Translators"/>
      <typeAlias alias="SetInteractionDetailsRequestTranslator" type="SEEDS.Translators.SetInteractionDetailsRequestTranslator, SEEDS.Translators"/>
      <typeAlias alias="GetSecurityTokenResponseTranslator" type="SEEDS.Translators.GetSecurityTokenResponseTranslator, SEEDS.Translators"/>
      <typeAlias alias="SetOrderDetailsResponseTranslator" type="SEEDS.Translators.SetOrderDetailsResponseTranslator, SEEDS.Translators"/>
      <typeAlias alias="SetInteractionDetailsResponseTranslator" type="SEEDS.Translators.SetInteractionDetailsResponseTranslator, SEEDS.Translators"/>
      <typeAlias alias="EntityReferenceTranslator" type="SEEDS.Translators.EntityReferenceTranslator, SEEDS.Translators"/>
    </typeAliases>
    <containers>
      <container>
        <types>
          <!-- Service maps -->
          <type type="IService`2[[CS_GetSecurityTokenRequest, CS_GetSecurityTokenResponse]], SEEDS.EntityContracts" mapTo="BS_GetSecurityTokenService`2, SEEDS.BusinessServices" />
          <type type="IService`2[[CS_SetOrderDetailsRequest, CS_SetOrderDetailsResponse]], SEEDS.EntityContracts" mapTo="BS_SetOrderDetailsService`2, SEEDS.BusinessServices" />
          <type type="IService`2[[CS_SetInteractionDetailsRequest, CS_SetInteractionDetailsResponse]], SEEDS.EntityContracts" mapTo="BS_SetInteractionDetailsService`2, SEEDS.BusinessServices" />
          <!-- ServiceLogging maps -->
          <type type="IService`2[[ServiceLogEntry`2, CS_GetSecurityTokenResponse]], SEEDS.EntityContracts" mapTo="BS_ServiceLogService`2, SEEDS.BusinessServices" />
          <type type="IService`2[[ServiceLogEntry`2, CS_SetOrderDetailsResponse]], SEEDS.EntityContracts" mapTo="BS_ServiceLogService`2, SEEDS.BusinessServices" />
          <type type="IService`2[[ServiceLogEntry`2, CS_SetInteractionDetailsResponse]], SEEDS.EntityContracts" mapTo="BS_ServiceLogService`2, SEEDS.BusinessServices" />
          <!-- ITranslator maps-->
          <type type="ITranslator`2[[CS_ErrorCollection, IErrorCollection]]" mapTo="ErrorCollectionTranslator" />
          <type type="ITranslator'2[[SM_Message, ServiceLogEntry`2]]" mapTo="ServiceLogEntryTranslator`2" />
          <type type="ITranslator`2[[BS_GetSecurityTokenRequest CS_GetSecurityTokenRequest]]" mapTo="GetSecurityTokenRequestTranslator" />
          <type type="ITranslator`2[[BS_SetOrderDetailsRequest, CS_SetOrderDetailsRequest]]" mapTo="SetOrderDetailsRequestTranslator" />
          <type type="ITranslator`2[[BS_SetInteractionDetailsRequest, CS_SetInteractionDetailsRequest]]" mapTo="SetInteractionDetailsRequestTranslator" />
          <type type="ITranslator`2[[CS_GetSecurityTokenResponse, BS_GetSecurityTokenResponse]]" mapTo="GetSecurityTokenResponseTranslator" />
          <type type="ITranslator`2[[CS_SetOrderDetailsResponse, BS_SetOrderDetailsResponse]]" mapTo="SetOrderDetailsResponseTranslator" />
          <type type="ITranslator`2[[CS_SetInteractionDetailsResponse, BS_SetInteractionDetailsResponse]]" mapTo="SetInteractionDetailsResponseTranslator" />
          <type type="ITranslator`2[[CS_SetOrderDetailsRequest, string]]" mapTo="SetOrderDetailsRequestTranslator" />
          <type type="ITranslator`2[[CS_SetOrderDetailsResponse, string]]" mapTo="SetOrderDetailsResponseTranslator" />
          <type type="ITranslator`2[[CS_SetInteractionDetailsRequest, string]]" mapTo="SetInteractionDetailsRequestTranslator" />
          <type type="ITranslator`2[[CS_SetInteractionDetailsResponse, string]]" mapTo="SetInteractionDetailsResponseTranslator" />
          <type type="ITranslator`2[[SM_EntityReference, EntityReference]]" mapTo="EntityReferenceTranslator" />
        </types>
      </container>
    </containers>
  </unity>

 


Apr 22, 2009 at 5:47 PM
Never mind. I solved it by getting rid of my type aliases and including the namespaces and assembly names. I'll have to add the aliases back one at a time to figure out what the problem is.

One other note for anyone that is new to Unity (like me).
The square bracket syntax for generic types is not documented well at all. If you are mapping a generic type with more than one type parameter, place brakets around both types. Like this... (whitespace added for readablity)

<

 

type
    
type=
        "SEEDS.EntityContracts.IService`2
        [
            [SEEDS.CommunicationServices.MessageContracts.GetSecurityTokenRequest, SEEDS.CommunicationServices.MessageContracts],
            [SEEDS.CommunicationServices.MessageContracts.GetSecurityTokenResponse, SEEDS.CommunicationServices.MessageContracts]
        ],
        SEEDS.EntityContracts
"
    
mapTo="SEEDS.BusinessServices.GetSecurityTokenService`2, SEEDS.BusinessServices" />