asp.net-mvc-3 – DotNetOpenAuth.Asp在MVC4应用程序单元测试中无法加载程序集或其依赖项之一

前端之家收集整理的这篇文章主要介绍了asp.net-mvc-3 – DotNetOpenAuth.Asp在MVC4应用程序单元测试中无法加载程序集或其依赖项之一前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的项目中面临着非常奇怪的错误.我安装了DotnetOpenAuth.Aspnet和Microsoft.AspNet.WebPages.OAuth库nuget包.当我运行项目没有问题.但是当我编写控制器的测试时,它会抛出如下的异常.

测试方法MvcApplication2.Tests.ControllerTest.should_return_not_empty_content抛出异常:

  1. System.IO.FileLoadException: Could not load file or assembly 'DotNetOpenAuth.AspNet,Version=4.0.0.0,Culture=neutral,PublicKeyToken=2780ccd10d57b246'
  2. 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,但它也没有工作.

您可以在以下行中找到所有项目和样本测试.它只是一个应用程序一个测试项目.很容易阅读

此外,我在这里添加了一个示例代码,用于控制器和失败的测试.

用于代码预览的pastebin链接http://pastebin.com/1PCpq3hW

任何帮助将不胜感激.

Vs2010和2012年projects不成功

详细的日志结果如下所示

  1.  
  2. *** Assembly Binder Log Entry (13.12.2012 @ 22:27:31) ***
  3.  
  4. The operation Failed.
  5. Bind result: hr = 0x80131040. No description available.
  6.  
  7. Assembly manager loaded from: C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
  8. Running under executable C:\Program Files (x86)\JetBrains\ReSharper\v7.0\Bin\JetBrains.ReSharper.TaskRunner.CLR4.exe
  9. --- A detailed error log follows.
  10.  
  11. === bind state information ===
  12. LOG: User = DEVELOPER-PC\DEVELOPER
  13. LOG: DisplayName = DotNetOpenAuth.AspNet,PublicKeyToken=2780ccd10d57b246
  14. (Fully-specified)
  15. LOG: Appbase = file:///D:/Development/Coachius/CoachiusWeb.Tests/bin/Debug
  16. LOG: Initial PrivatePath = NULL
  17. LOG: Dynamic Base = NULL
  18. LOG: Cache Base = NULL
  19. LOG: AppName = NULL
  20. Calling assembly : CoachiusWeb,Version=1.0.0.0,PublicKeyToken=null.
  21. ===
  22. LOG: This bind starts in default load context.
  23. LOG: Using application configuration file: D:\Development\Coachius\CoachiusWeb.Tests\bin\Debug\CoachiusWeb.Tests.dll.config
  24. LOG: Using host configuration file:
  25. LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
  26. LOG: Post-policy reference: DotNetOpenAuth.AspNet,PublicKeyToken=2780ccd10d57b246
  27. LOG: GAC Lookup was unsuccessful.
  28. LOG: Attempting download of new URL file:///D:/Development/Coachius/CoachiusWeb.Tests/bin/Debug/DotNetOpenAuth.AspNet.DLL.
  29. LOG: Assembly download was successful. Attempting setup of file: D:\Development\Coachius\CoachiusWeb.Tests\bin\Debug\DotNetOpenAuth.AspNet.dll
  30. LOG: Entering run-from-source setup phase.
  31. LOG: Assembly Name is: DotNetOpenAuth.AspNet,Version=4.1.0.0,PublicKeyToken=2780ccd10d57b246
  32. WRN: Comparing the assembly name resulted in the mismatch: Minor Version
  33. ERR: The assembly reference did not match the assembly definition found.
  34. ERR: Run-from-source setup phase Failed with hr = 0x80131040.
  35. ERR: Failed to complete setup of assembly (hr = 0x80131040). Probing terminated.
  36.  

解决方法

我已经解决
  1. <configuration>
  2. <runtime>
  3. <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
  4. <dependentAssembly>
  5. <assemblyIdentity name="DotNetOpenAuth.AspNet" publicKeyToken="2780ccd10d57b246" culture="neutral" />
  6. <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
  7. </dependentAssembly>
  8. <dependentAssembly>
  9. <assemblyIdentity name="DotNetOpenAuth.Core" publicKeyToken="2780ccd10d57b246" culture="neutral" />
  10. <bindingRedirect oldVersion="0.0.0.0-4.3.0.0" newVersion="4.3.0.0" />
  11. </dependentAssembly>
  12. <dependentAssembly>
  13. <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" culture="neutral" />
  14. <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
  15. </dependentAssembly>
  16. </assemblyBinding>
  17. </runtime>
  18. </configuration>

猜你在找的asp.Net相关文章