knut.tveitane
knut.tveitane

Reputation: 41

TypeInitializationException in PostSharp

I have added PostSharp (4.0.37) and PostSharp.Patterns.Model to my project. It then compiles and runs fine.

I then add the [NotifyPropertyChanged] to my very simple scaled-down example class (containing only a single int32 auto-property). The project still compiles, but it throws a TypeInitializationException on startup:

An unhandled exception of type 'System.TypeInitializationException' occurred in Microsoft.VisualStudio.HostingProcess.Utilities.dll

Additional information: The type initializer for '<Module>' threw an exception.

VS 2012.4, Win7(x64), have tried .net 4, 4.5, 4.51 and 3.5, same thing happens. Any ideas?

Upvotes: 0

Views: 1702

Answers (1)

knut.tveitane
knut.tveitane

Reputation: 41

I think I found out: From some reason, NuGet first installed the alpha version of PostSharp (4.1.4.0) which didn't work for me (compile errors). When I discovered the version issue, I uninstalled it and took great care to install the stable version instead. However, I just realised there was still a setting left in the app.config file:

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="PostSharp" publicKeyToken="b13fd38b8f9c99d7" culture="neutral"/>
        <bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0"/>
      </dependentAssembly>
    </assemblyBinding>
  </runtime>

I removed the entire section, and my test app with my tiny little class in it now runs!

Upvotes: 2

Related Questions