Mark Kosyk
Mark Kosyk

Reputation: 125

AssemblyLoadException in PostSharp on release build

I have a couple of projects that all include the json.net 6.0.3 NuGet package. When I add:

using Newtonsoft.Json;

I get the following error when building:

1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: Unhandled exception (3.1.48.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'newtonsoft.json, version=4.5.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed'. [Version mismatch] 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: ============ PostSharp Assembly Loading Log =================== 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Finding the assembly with binding identity 'newtonsoft.json, version=4.5.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed'. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Found file 'F:\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll' with identity 'newtonsoft.json, version=6.0.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed, processorarchitecture=msil'. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Reference mismatch for 'F:\packages\Newtonsoft.Json.6.0.3\lib\net45\Newtonsoft.Json.dll' [VersionMismatch]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\ProgramData\PostSharp\3.1.48\bin.Release\Newtonsoft.Json.exe' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\ProgramData\PostSharp\3.1.48\bin.Release\Newtonsoft.Json.dll' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\ProgramData\PostSharp\3.1.48\bin.Release\Newtonsoft.Json.winmd' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'F:\bin\release\TwinkyTalk\Newtonsoft.Json.exe' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Found file 'F:\bin\release\TwinkyTalk\Newtonsoft.Json.dll' with identity 'newtonsoft.json, version=6.0.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed, processorarchitecture=msil'. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Reference mismatch for 'F:\bin\release\TwinkyTalk\Newtonsoft.Json.dll' [VersionMismatch]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'F:\bin\release\TwinkyTalk\Newtonsoft.Json.winmd' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'F:\TwinkyTalk\obj\Release\Newtonsoft.Json.exe' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'F:\TwinkyTalk\obj\Release\Newtonsoft.Json.dll' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'F:\TwinkyTalk\obj\Release\Newtonsoft.Json.winmd' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Newtonsoft.Json.exe' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Newtonsoft.Json.dll' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Newtonsoft.Json.winmd' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\Newtonsoft.Json.exe' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\Newtonsoft.Json.dll' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.5.1\Facades\Newtonsoft.Json.winmd' because this directory was explicitly added to the search path [File Not Found]. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Looking in GAC for Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=x86. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Looking in GAC for Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=msil. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: Looking in GAC for Newtonsoft.Json, Version=4.5.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: LOG: The assembly 'newtonsoft.json, version=4.5.0.0, culture=neutral, publickeytoken=30ad4fe6b2a6aeed' was not found. 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: =============================================================== 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions) 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.^5YpB0scd(BindingOptions _0) 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.^SgrhoGlQ(AssemblyRefDeclaration _0) 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.^+GwnKh4ZYHu3() 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Tasks.MulticastAttributeTask.Execute() 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase) 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Sdk.Extensibility.Project.Execute() 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Hosting.PostSharpObject.ExecuteProjects() 1>F:\TwinkyTalk\TwinkyTalk.csproj : error PS0099: at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation).

I was unable to find any references to "'newtonsoft.json, version=4.5.0.0," in the project, not sure why it is looking for that.

I tried setting the "Build Host" PostSharp project property to managed but still got the same exception.

Upvotes: 2

Views: 2140

Answers (2)

Mark Kosyk
Mark Kosyk

Reputation: 125

Turns out that while the exception was coming from PostSharp the remedy was updating all the NuGet packages.

Upvotes: 0

AlexD
AlexD

Reputation: 5101

This usually can happen when some of the 3-rd party libraries reference an older version of the assembly (Newtonsoft.Json in this case). The problem is solved by specifying a binding redirect in your web.config/app.config file.

<dependentAssembly>
  <assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/>
  <bindingRedirect oldVersion="0.0.0.0-6.0.3.0" newVersion="6.0.3.0"/>
</dependentAssembly>

However, you also need to tell PostSharp where to look for binding redirect configuration. You can do this by setting PostSharpHostConfigurationFile property in your *.csproj file:

<PropertyGroup>
  <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
</PropertyGroup>

There's another similar question on SO (PostSharp AssemblyLoadException Autofac), and a relevant blog post.

Upvotes: 6

Related Questions