我的项目中遇到了非常奇怪的错误。我安装了 DotnetOpenAuth.Aspnet 和 Microsoft.AspNet.WebPages.OAuth 库 nuget 包。当我运行该项目时没有问题。但是当我为 Controller 编写测试时,它会抛出如下异常。
测试方法 MvcApplication2.Tests.ControllerTest.should_return_not_empty_content 引发异常:
System.IO.FileLoadException: Could not load file or assembly 'DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246'
or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
另一个奇怪的点是,如果我在 VS 2010 中设置一个项目作为 MVC3 应用程序并且测试正在通过。没有失败。但是当我在 VS2012 中进行完全相同的设置时,它会引发与上面相同的错误。 当我在 stackoverflow 上搜索时,我看到了这个 solution但它也不起作用。
您可以在以下几行中找到所有项目和示例测试。这只是一个应用程序一个测试项目。非常容易阅读。
我还在这里添加了 Controller 和失败测试的示例代码。
代码预览的pastebin链接是http://pastebin.com/1PCpq3hW
如有任何帮助,我们将不胜感激。
对比2010年和2012年的失败和成功projects
详细的日志结果如下所示
*** Assembly Binder Log Entry (13.12.2012 @ 22:27:31) *** The operation failed. Bind result: hr = 0x80131040. No description available. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll Running under executable C:\Program Files (x86)\JetBrains\ReSharper\v7.0\Bin\JetBrains.ReSharper.TaskRunner.CLR4.exe --- A detailed error log follows. === bind state information === LOG: User = DEVELOPER-PC\DEVELOPER LOG: DisplayName = DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246 (Fully-specified) LOG: Appbase = file:///D:/Development/Coachius/CoachiusWeb.Tests/bin/Debug LOG: Initial PrivatePath = NULL LOG: Dynamic Base = NULL LOG: Cache Base = NULL LOG: AppName = NULL Calling assembly : CoachiusWeb, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null. === LOG: This bind starts in default load context. LOG: Using application configuration file: D:\Development\Coachius\CoachiusWeb.Tests\bin\Debug\CoachiusWeb.Tests.dll.config LOG: Using host configuration file: LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config. LOG: Post-policy reference: DotNetOpenAuth.AspNet, Version=4.0.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246 LOG: GAC Lookup was unsuccessful. LOG: Attempting download of new URL file:///D:/Development/Coachius/CoachiusWeb.Tests/bin/Debug/DotNetOpenAuth.AspNet.DLL. LOG: Assembly download was successful. Attempting setup of file: D:\Development\Coachius\CoachiusWeb.Tests\bin\Debug\DotNetOpenAuth.AspNet.dll LOG: Entering run-from-source setup phase. LOG: Assembly Name is: DotNetOpenAuth.AspNet, Version=4.1.0.0, Culture=neutral, PublicKeyToken=2780ccd10d57b246 WRN: Comparing the assembly name resulted in the mismatch: Minor Version ERR: The assembly reference did not match the assembly definition found. ERR: Run-from-source setup phase failed with hr = 0x80131040. ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
最佳答案
我已经解决了
<configuration>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
关于asp.net-mvc-3 - DotNetOpenAuth.Asp 无法在 MVC4 应用程序单元测试中加载程序集或其依赖项之一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13863478/