PostSharp.Sdk.CodeModel.AssemblyLoadException:找不到程序集' mscorlib,version = 2.0.5.0

时间:2014-10-17 21:28:21

标签: c# postsharp

最近更新到Windows 8.1后,我的VS 2013不再编译我的解决方案。

Error   1   Unhandled exception (2.1.7.35, 32 bit, CLR 4.0, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e'. [Public key mismatch]
============ PostSharp Assembly Loading Log ===================
LOG: Finding the assembly with binding identity 'mscorlib, version=2.0.5.0, culture=neutral, publickeytoken=7cec85d7bea7798e'.
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' because this file was explicitly added to the search path.
LOG: File 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' has identity 'mscorlib, version=4.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089, processorarchitecture=msil'.
LOG: File 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.0\mscorlib.dll' does not match the reference.
...
LOG: The assembly 'mscorlib_7' was not found.
===============================================================
   at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions)
   at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.GetAssemblyEnvelope()
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition(BindingOptions bindingOptions)
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition()
   at ^I3av2ouCqwmI.^4+F3cylo(INamedType _0, INamedType _1, BindingOptions _2)
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.^A9yFoe2uB3TC(ITypeSignature _0, BindingOptions _1)
   at ^I3av2ouCqwmI.^4+F3cylo(IMethodSignature _0, IMethodSignature _1, BindingOptions _2)
   at PostSharp.Sdk.CodeModel.Binding.MethodSignatureComparer.Equals(IMethodSignature x, IMethodSignature y)
   at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
   at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
   at ^/vWxD3eYDOIx.^wdkNIZCy[??0](^/fRRnkiTvxqu _0, ??0 _1, ^EyL1LQX01Ck8 _2, ^0RC0kpHqS6Uy _3, Dictionary`2 _4, Int32 _5, Int32 _6)
   at PostSharp.Sdk.Binary.ModuleWriter.SetMemberSignatureIndex(MemberRefDeclaration _0, ^EyL1LQX01Ck8 _1, ^0RC0kpHqS6Uy _2)
   at PostSharp.Sdk.Binary.ModuleWriter.WriteMemberRef(MemberRefDeclaration _0, MetadataToken _1)
   at PostSharp.Sdk.Binary.ModuleWriter.GetMappedDeclarationToken(MetadataDeclaration _0)
   at PostSharp.Sdk.Binary.ModuleWriter.SetMappedMetadataToken(MetadataDeclaration _0, UInt32* _1)
   at ^R00FfLNj7vE0.^rk33N/hO(OpCodeNumber _0, MetadataDeclaration _1)
   at ^R00FfLNj7vE0.EmitInstructionMethod(OpCodeNumber _0, IMethod _1)
   at PostSharp.Sdk.CodeModel.Instruction.Write(BaseInstructionWriter writer, InstructionPrefixes allowedPrefixes)
   at ^zpGNRK5nUM9z.^x98p/iJs13L+(InstructionReader _0)
   at PostSharp.Sdk.CodeModel.MethodBodyDeclaration.^uPrQJ6gs(InstructionBlock _0, IMethodBodyVisitor[] _1, MethodBodyVisitLevel _2, InstructionAction _3, InstructionReader _4, InstructionBlockExceptionHandlingKind _5)
   at PostSharp.Sdk.CodeModel.MethodBodyDeclaration.^uPrQJ6gs(InstructionBlock _0, IMethodBodyVisitor[] _1, MethodBodyVisitLevel _2, InstructionAction _3, InstructionReader _4, InstructionBlockExceptionHandlingKind _5)
   at PostSharp.Sdk.CodeModel.MethodBodyDeclaration.^uPrQJ6gs(InstructionBlock _0, IMethodBodyVisitor[] _1, MethodBodyVisitLevel _2, InstructionAction _3, InstructionReader _4, InstructionBlockExceptionHandlingKind _5)
   at PostSharp.Sdk.CodeModel.MethodBodyDeclaration.^uPrQJ6gs(InstructionBlock _0, IMethodBodyVisitor[] _1, MethodBodyVisitLevel _2, InstructionAction _3, InstructionReader _4, InstructionBlockExceptionHandlingKind _5)
   at ^zpGNRK5nUM9z.^e2BtLyuT(^Kh85h0nXrulm& _0, Int32& _1)
   at ^zpGNRK5nUM9z.^SkiT(^ceSOybcTEumb _0)
   at PostSharp.Sdk.Binary.ModuleWriter.WriteMethodBodies(^ceSOybcTEumb _0, UInt32 _1)
   at ^Up6wxUIUnN6a.^VfvrABjR()
   at ^Up6wxUIUnN6a.^SkiT()
   at ^cyC/TYSlPGB/.^wvPm(^RtksFin57NJ8 _0, ^8gP93Xsl\+Imn _1)
   at PostSharp.Sdk.Extensibility.Tasks.CompileTask.Execute()
   at PostSharp.Sdk.Extensibility.Project.ExecutePhase(String phase)
   at PostSharp.Sdk.Extensibility.Project.Execute()
   at PostSharp.Hosting.PostSharpObject.ExecuteProjects()
   at PostSharp.Hosting.PostSharpObject.InvokeProject(ProjectInvocation projectInvocation)  E:\Development.TFS\CopyTran\MAIN\CopyTran\CopyTran.CoreDatabase\POSTSHARP   CopyTran.CoreDatabase

任何可能导致此行为的想法?具有相同VS2013和代码的Windows 7机器可以正常工作。

更新

一旦我添加了这段代码,就会重新出现编译错误:

TypeMap[] allTypeMaps = Mapper.GetAllTypeMaps();
foreach (TypeMap typeMap in allTypeMaps)
{
    foreach (PropertyMap propertyMap in typeMap.GetPropertyMaps())
    {
        if ((propertyMap.SourceMember as PropertyInfo).PropertyType.Name !=
            propertyMap.DestinationPropertyType.Name)
        {
            _log.WarnFormat("Types not matching {0}.{1} <> {2}.{3}", typeMap.SourceType.Name,
            propertyMap.SourceMember.Name, typeMap.DestinationType.Name,
            propertyMap.DestinationProperty.Name);
        }
    }
}

_log是来自Log4Net的ILog,但它在其他地方使用没有任何问题。

4 个答案:

答案 0 :(得分:2)

我在.Net 4.5.1项目中解决了这个问题(针对不同的程序集),将以下内容添加到

<DontImportPostSharp>True</DontImportPostSharp>
<PostSharpTargetFrameworkVersion>4.0</PostSharpTargetFrameworkVersion>

答案 1 :(得分:1)

PostSharp 2.1不支持Windows 8.1。最新支持的版本是Windows 7.您应该升级到PostSharp 3.1。此外,我发现你的目标是PCL,并且PostSharp 3.1中的PCL支持得到了很大的改进。

答案 2 :(得分:0)

在TeamCity构建服务器上出现此问题。

尝试enter image description here无济于事后,我浏览了损坏项目的引用程序集,并用this answer检查了它们,以检查哪个引用了mscorlib 2.0.5.0

罪魁祸首是Autofac 3.3.0.0

将nuget软件包更新为Autofac 4.8.1.0解决了该问题。

答案 3 :(得分:0)

再次出现此问题,但是由于解决方案已锁定到MVC4,因此无法升级到Autofac 4。

这次的解决方法是将C:\ProgramData\PostSharp\BindingMaps从我的本地计算机复制到构建服务器