.Net核心测试项目不断丢失系统参考

时间:2016-07-06 12:21:03

标签: c# asp.net-core-mvc

我创建了一个简单的.net核心MVC Web服务。当我运行它时工作正常。

我添加了一个测试项目和几个测试,一切正常。

今天早上我重构了我的web服务,以便我使用的dao代码被移动到一个单独的程序集中。一旦我这样做,我就开始得到http500错误,我的测试项目将不再运行。

  

System.IO.FileNotFoundException:无法加载文件或程序集   'System.Runtime,Version = 4.1.0.0,Culture = neutral,   PublicKeyToken = b03f5f7f11d50a3a'或其依赖项之一。该   系统找不到指定的文件。

快速谷歌没有改变任何东西,所以我删除了对我的dao汇编项目的引用,并将我的所有代码复制回原始项目。现在原始项目工作,但我仍然在测试项目中遇到绑定错误。 Fusion显示错误;

Test method TestService_Tests.ControllerTests.TestGetEnquiries threw exception: 
System.IO.FileNotFoundException: Could not load file or assembly 'System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe

A detailed error log follows. 

Pre-bind state information ===
LOG: DisplayName = System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///c:/users/matt/documents/visual studio 2015/Projects/TestService/TestService_Tests/bin/Debug
LOG: Initial PrivatePath = NULL
Calling assembly : ReportingService, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null.
LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.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: System.Runtime, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: The same bind was seen before, and was failed with hr = 0x80070002.

我认为在添加.net核心程序集时,我在某处导致了配置问题。但是如何跟踪它,除了删除测试项目,再次启动并希望配置问题出现在测试项目中?

通过反复试验我可以说错误发生在它调用控制器的行上。 不测试控制器工作的虚拟测试。但是,只要对我的任何代码进行测试,就会出现问题。

{
"dependencies": {
"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.Logging": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
"ReportingBusinessLayer": "1.0.0-*",
"System.Runtime": "4.1.0" },

"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
},

"frameworks": {
"netcoreapp1.0": {
  "imports": [
    "dotnet5.6",
    "portable-net45+win8"
  ]
}
},

"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},

"runtimeOptions": {
"configProperties": {
  "System.GC.Server": true
}
},

"publishOptions": {
"include": [
  "wwwroot",
  "Views",
  "Areas/**/Views",
  "appsettings.json",
  "web.config"
]
},

"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder  publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}

1 个答案:

答案 0 :(得分:0)

检查您的复印本地设置。通常,在重构之后引用无法解决时,由于本地复制本地为假,或者引用未被添加到提供者和消费者项目中。我不认为这对于这个系统库是必要的,但它值得检查,因为我不知道你有什么其他框架。

另外,请确保您的提供程序库未针对与消费者不同的程序集或.NET运行时版本。