我保留了PostSharp.Toolkit.Threading,版本2.1.1.12的NuGet包,因为我无法升级到版本3.x.任何项目编译都很好,只要我保持.Net 4或4.5,但是一旦我改为4.5.1或4.5.2,我就会收到这个错误:
Error 3 error: Unhandled exception (2.1.7.35, 32 bit, CLR 2.0, Release): Cannot load assembly T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll.
============ PostSharp Assembly Loading Log ===================
LOG: NativeDotNetPlatform.LoadAssemblyFromFile: T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll.
LOG: Assembly identity returned by the host: postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil.
LOG: Assembly 'postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil' is not yet loaded in the AppDomain.
LOG: Invoking Assembly.Load({postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil})
LOG: (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil".
LOG: Finding the assembly with binding identity 'postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil'.
LOG: Location found from cache: 'T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll'.
LOG: (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": assembly found in search path.
LOG: (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": located in "T:\WindowsFormsApplication4\packages\PostSharp.Toolkit.Threading.2.1.1.12\tools\PostSharp.Toolkit.Threading.Weaver.dll".
LOG: (ClrHost) ProvideAssembly: "postsharp.toolkit.threading.weaver, version=0.0.0.0, culture=neutral, publickeytoken=null, processorarchitecture=msil": returned successfully.
LOG: AssemblyLoadException: Could not load file or assembly 'postsharp.toolkit.threading.weaver, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
LOG: Loaded: 'mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll'.
LOG: Loaded: 'PostSharp.Hosting, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Hosting.dll'.
LOG: Loaded: 'System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System.Core\3.5.0.0__b77a5c561934e089\System.Core.dll'.
LOG: Loaded: 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System\2.0.0.0__b77a5c561934e089\System.dll'.
LOG: Loaded: 'PostSharp.Sdk, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Sdk.dll'.
LOG: Loaded: 'PostSharp.Settings, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Settings.dll'.
LOG: Loaded: 'PostSharp, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.dll'.
LOG: Loaded: 'System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' from 'C:\Windows\assembly\GAC_MSIL\System.Xml\2.0.0.0__b77a5c561934e089\System.Xml.dll'.
LOG: Loaded: 'System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' from 'C:\Windows\assembly\GAC_MSIL\System.Configuration\2.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'.
LOG: Loaded: 'PostSharp.Pipe, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Pipe.dll'.
LOG: Loaded: 'PostSharp.Sdk.XmlSerializers, Version=2.1.0.0, Culture=neutral, PublicKeyToken=b13fd38b8f9c99d7' from 'T:\WindowsFormsApplication4\packages\PostSharp.2.1.7.35\tools\Release\PostSharp.Sdk.XmlSerializers.dll'.
=============================================================== See below for details. T:\WindowsFormsApplication4\WindowsFormsApplication4\POSTSHARP WindowsFormsApplication4
我无法弄清楚为什么会发生这种情况。那里有P#大师吗?
答案 0 :(得分:4)
日志显示托管CLR版本的PostSharp为2.0。在加载线程编织程序集时,CLR还会尝试加载一些需要CLR 4.0的依赖项。这是你得到例外的时候。
PostSharp 2.x可识别目标框架4.5并自动选择托管CLR 4.0,但无法识别较新的框架版本4.5.1,默认情况下使用CLR 2.0。
您可以通过将MSBuild属性PostSharpTargetFrameworkVersion
设置为4.0来覆盖托管CLR。