Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/329.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 当没有项目引用system.web.mvc(版本=3.0.0.0)的程序集时,PostSharp的问题无法找到该程序集_C#_Asp.net Mvc_Asp.net Mvc 4_Aop_Postsharp - Fatal编程技术网

C# 当没有项目引用system.web.mvc(版本=3.0.0.0)的程序集时,PostSharp的问题无法找到该程序集

C# 当没有项目引用system.web.mvc(版本=3.0.0.0)的程序集时,PostSharp的问题无法找到该程序集,c#,asp.net-mvc,asp.net-mvc-4,aop,postsharp,C#,Asp.net Mvc,Asp.net Mvc 4,Aop,Postsharp,我用的是PostSharp,效果很好。最近,我们将一些项目升级到MVC版本5.2。今天,我加载了一个使用MVC 4.0版本的旧项目。PostSharp开始在生成时报告一个奇怪的错误: Error 17 Unhandled exception (3.1.42.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'system.web.mvc, ver

我用的是PostSharp,效果很好。最近,我们将一些项目升级到MVC版本5.2。今天,我加载了一个使用MVC 4.0版本的旧项目。PostSharp开始在生成时报告一个奇怪的错误:

Error   17  Unhandled exception (3.1.42.0, 32 bit, CLR 4.5, Release): PostSharp.Sdk.CodeModel.AssemblyLoadException: Cannot find assembly 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'. [Version mismatch]
============ PostSharp Assembly Loading Log ===================
LOG: Finding the assembly with binding identity 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35'.
LOG: Found file 'C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll' with identity 'system.web.mvc, version=4.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35, processorarchitecture=msil'.
LOG: Reference mismatch for 'C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET MVC 4\Assemblies\System.Web.Mvc.dll' [VersionMismatch].
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\ProgramData\PostSharp\3.1.42\bin.Release\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\bin\Debug\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\obj\Debug\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.exe' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.dll' because this directory was explicitly added to the search path [File Not Found].
LOG: Probing location 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.1\Facades\System.Web.Mvc.winmd' because this directory was explicitly added to the search path [File Not Found].
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=x86.
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=msil.
LOG: Looking in GAC for System.Web.Mvc, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35.
LOG: The assembly 'system.web.mvc, version=3.0.0.0, culture=neutral, publickeytoken=31bf3856ad364e35' was not found.
===============================================================
   at PostSharp.Sdk.CodeModel.Domain.GetAssembly(IAssemblyName assemblyName, BindingOptions bindingOptions)
   at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.^5YpB0scd(BindingOptions _0)
   at PostSharp.Sdk.CodeModel.AssemblyRefDeclaration.GetAssemblyEnvelope(BindingOptions bindingOptions)
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition(BindingOptions bindingOptions)
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.GetTypeDefinition()
   at PostSharp.Sdk.CodeModel.CompareExtensions.DefinitionMatchesReference(INamedType definition, INamedType reference, BindingOptions options)
   at PostSharp.Sdk.CodeModel.TypeRefDeclaration.^A9yFoe2uB3TC(ITypeSignature _0, BindingOptions _1)
   at PostSharp.Sdk.CodeModel.CompareExtensions.DefinitionMatchesReference(IMethodSignature definition, IMethodSignature reference, BindingOptions options)
   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 ^zpGNRK5nUM9z.^e2BtLyuT(^Kh85h0nXrulm& _0, Int32& _1)
   at ^zpGNRK5nUM9z.^SkiT(BufferWriter _0)
   at PostSharp.Sdk.Binary.ModuleWriter.WriteMethodBodies(BufferWriter _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). C:\Work\Work\CodeBase\C#\CS\+Frameworks\v5\BusinessLogic_CS_v5\BusinessLogic_CS_v5.csproj   BusinessLogic_CS_v5
我浏览了所有的项目参考资料,没有一个项目参考了
system.web.mvc,version=3.0.0.0
。所有项目都参考
4.0.0.0
。为什么提到3.0.0.0版?它可能是从某个GAC或某个本地安装中找到的吗


如果从项目属性禁用PostSharp,则项目将成功编译。所以一定是跟PostSharp有关。任何帮助都将不胜感激,因为我不知道Postsharp可能在内部引用MVC 3。您可以在web.config中尝试绑定重定向:

<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
        <dependentAssembly>
            <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
            <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
        </dependentAssembly>
    </assemblyBinding>
</runtime>

当某些第三方程序集引用较旧版本的System.Web.Mvc时,通常会出现此错误。您的web.config中有绑定重定向,但您还需要告诉PostSharp在构建期间使用该配置。您可以通过将
PostSharpHostConfigurationFile
build属性设置为*.config文件的路径来完成此操作

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

web.config

在[project].csproj文件中添加以下代码。要实现此目的,请执行以下步骤:

  • 在项目中单击鼠标右键
  • 卸载项目
  • 然后在卸载的项目中单击鼠标右键,然后单击编辑[project].csproj
  • 查找标记
    您正在使用的库之一很可能是引用3.0。您可以查看更多信息的一个地方是fusion日志查看器,在我的例子中,添加PostSharp NuGet直接解决了这个问题!(v4.3.3)这已经存在于web.config/app.config中,问题仍然存在。实际上,将其添加到csproj文件中修复了问题,但确实有帮助!由于一个正确的假设,即不是每个人都会自动知道将PropertyGroup放置在何处,所以进行了向上投票。谢谢你帮我节省了时间。工作得很有魅力
    
    <PropertyGroup>
        <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
    </PropertyGroup>
    
    <Import Project="..\..\packages\PostSharp.4.0.42\tools\PostSharp.targets" Condition="Exists('..\..\packages\PostSharp.4.0.42\tools\PostSharp.targets')" />
    <PropertyGroup>
        <PostSharpHostConfigurationFile>web.config</PostSharpHostConfigurationFile>
    </PropertyGroup>