Unable to load one or more of the requested types - Upgrade to 6.0.0

Hi,

I recently upgrade a project from nSericeBus 5.29 -> 6.0.0. When I try and deploy I get the below error:

[NServiceBus.Endpoint.Install] Unhandled Exception: System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types. Retrieve the LoaderExceptions property for more information.
[NServiceBus.Endpoint.Install]    at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
[NServiceBus.Endpoint.Install]    at System.Reflection.Assembly.GetTypes()
[NServiceBus.Endpoint.Install]    at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.<>c.<ScanAssembliesForEndpoints>b__10_0(Assembly assembly) in C:\Build\src\NServiceBus.Hosting.Windows\EndpointTypeDeterminer.cs:line 159
[NServiceBus.Endpoint.Install]    at System.Linq.Enumerable.<SelectManyIterator>d__17`2.MoveNext()
[NServiceBus.Endpoint.Install]    at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
[NServiceBus.Endpoint.Install]    at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
[NServiceBus.Endpoint.Install]    at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.TryGetEndpointConfigurationTypeFromScannedAssemblies(Type& type) in C:\Build\src\NServiceBus.Hosting.Windows\EndpointTypeDeterminer.cs:line 127
[NServiceBus.Endpoint.Install]    at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.GetEndpointConfigurationType(HostArguments arguments) in C:\Build\src\NServiceBus.Hosting.Windows\EndpointTypeDeterminer.cs:line 81
[NServiceBus.Endpoint.Install]    at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(HostArguments arguments) in C:\Build\src\NServiceBus.Hosting.Windows\EndpointTypeDeterminer.cs:line 50
[NServiceBus.Endpoint.Install]    at NServiceBus.Hosting.Windows.Program.Main(String[] args) in C:\Build\src\NServiceBus.Hosting.Windows\HostProgram.cs:line 3

The event viewer logs showed this error:

Application: NServiceBus.Host.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.Reflection.ReflectionTypeLoadException
   at System.Reflection.RuntimeModule.GetTypes(System.Reflection.RuntimeModule)
   at System.Reflection.Assembly.GetTypes()
   at NServiceBus.Hosting.Windows.EndpointTypeDeterminer+<>c.<ScanAssembliesForEndpoints>b__10_0(System.Reflection.Assembly)
   at System.Linq.Enumerable+<SelectManyIterator>d__17`2[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]].MoveNext()
   at System.Collections.Generic.List`1[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]..ctor(System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at System.Linq.Enumerable.ToList[[System.__Canon, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]](System.Collections.Generic.IEnumerable`1<System.__Canon>)
   at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.TryGetEndpointConfigurationTypeFromScannedAssemblies(System.Type ByRef)
   at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.GetEndpointConfigurationType(NServiceBus.Hosting.Windows.Arguments.HostArguments)
   at NServiceBus.Hosting.Windows.EndpointTypeDeterminer.GetEndpointConfigurationTypeForHostedEndpoint(NServiceBus.Hosting.Windows.Arguments.HostArguments)
   at NServiceBus.Hosting.Windows.Program.Main(System.String[])

I have bindings re-direct in my app.config:

<runtime>
  <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
    <dependentAssembly>
      <assemblyIdentity name="NServiceBus.Core" publicKeyToken="9fc386479f8a226c" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="log4net" publicKeyToken="669e0ddf0bb1aa2a" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-2.0.8.0" newVersion="2.0.8.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="NHibernate" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.1.0.4000" newVersion="4.1.0.4000" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="RabbitMQ.Client" publicKeyToken="89e7d7c5feba84ce" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="NServiceBus.Transports.RabbitMQ" publicKeyToken="9fc386479f8a226c" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Castle.Windsor" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Castle.Core" publicKeyToken="407dd0808d44fbdc" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
    </dependentAssembly>
    <dependentAssembly>
      <assemblyIdentity name="Iesi.Collections" publicKeyToken="aa95f207798dfdb4" culture="neutral" />
      <bindingRedirect oldVersion="0.0.0.0-4.0.0.4000" newVersion="4.0.1.4000" />
    </dependentAssembly>
  </assemblyBinding>
</runtime>

My packages.config looks like below:

<package id="Castle.Core" version="4.2.0" targetFramework="net452" />
<package id="Castle.Windsor" version="3.3.0" targetFramework="net452" />
<package id="Iesi.Collections" version="4.0.1.4000" targetFramework="net452" />
<package id="log4net" version="2.0.8" targetFramework="net452" />
<package id="log4net.Ext.Json.1.2.13" version="1.2.13.20140804" targetFramework="net452" />
<package id="Microsoft.Diagnostics.Tracing.EventSource.Redist" version="1.1.28" targetFramework="net452" />
<package id="NHibernate" version="4.0.4.4000" targetFramework="net452" />
<package id="NServiceBus" version="6.0.0" targetFramework="net452" />
<package id="NServiceBus.CastleWindsor" version="6.0.0" targetFramework="net452" />
<package id="NServiceBus.Host" version="7.0.0" targetFramework="net452" />
<package id="NServiceBus.Log4Net" version="2.0.0" targetFramework="net452" />
<package id="NServiceBus.NHibernate" version="7.0.1" targetFramework="net452" />
<package id="NServiceBus.RabbitMQ" version="4.1.0" targetFramework="net452" />
<package id="NServiceBus.Testing" version="6.0.1" targetFramework="net452" />
<package id="RabbitMQ.Client" version="4.1.1" targetFramework="net452" />

I have tried changing the Iesi.Collections as mentioned in one of the other threads (I upgraded from 4.0.0 => 4.0.1) but no luck

So it turns out I needed these binding re-directs in the nservicebus.host.exe.config rather than in app.config. Which seems to helped with some issues. Still trying to resolve the others.

Correct, binding redirects must be in the config of the host executable which in this case is NServiceBus.Host.exe if you use the host.

Also see:

What other issue do you have?

Hi, The other issues were related to miss-match of reference configurations in .csproj and assembly reference and packages.config. Nothing to do with nServiceBus :grinning:

1 Like