運行時對我的Asp.Net核心Web應用程序(.NET Framework)的單元測試4.6我得到以下錯誤:錯誤的Asp.Net核心的Web應用程序運行單元測試(.NET框架)4.6
Test Name: Test1
Test FullName: UnitTest.Class1.Test1
Test Outcome: Failed
Test Duration: 0:00:00.015
Result StackTrace: at UnitTest.Class1.Test1()
Result Message: System.BadImageFormatException : Could not load file or
assembly 'MyWebApplication, Version=1.0.0.0, Culture=neutral,
PublicKeyToken=null' or one of its dependencies. An attempt was made to
load a program with an incorrect format.
我的單元測試應用程序是一個面向.NET Framework 4.6的.NET核心庫。
這裏是我的Asp.Net核心Web應用程序(.NET框架)4.6 project.json:
{
"dependencies": {
"Microsoft.AspNetCore.Diagnostics": "1.0.0",
"Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
"Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
"Microsoft.Extensions.Logging.Console": "1.0.0",
"Microsoft.Extensions.Logging.Debug": "1.0.0",
"Microsoft.Extensions.Configuration": "1.0.0",
"Microsoft.Extensions.Configuration.Json": "1.0.0",
"Microsoft.Extensions.DependencyInjection": "1.0.0",
"Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
"Microsoft.AspNetCore.StaticFiles": "1.0.0",
"Microsoft.AspNetCore.Mvc": "1.0.0",
"Microsoft.AspNetCore.Mvc.TagHelpers": "1.0.0",
"Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
},
"tools": {
"Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2- final"
},
"frameworks": {
"net46": {
"dependencies": {
"MyWebApplication": {
"target": "project"
}
},
"frameworkAssemblies": {
}
}
},
"buildOptions": {
"emitEntryPoint": true,
"preserveCompilationContext": true
},
"publishOptions": {
"include": [
"wwwroot",
"web.config",
"Views",
"appsettings.json"
]
},
"scripts": {
"postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
}
}
這裏是我的單元測試項目,這是一個.NET核心的project.json類庫目標的.NET Framework 4.6:
{
"version": "1.0.0-*",
"dependencies": {
"MyWebApplication": "1.0.0-*",
"NUnit": "3.5.0",
"NUnit.Runners": "2.6.4",
"NUnit3TestAdapter": "3.5.0"
},
"frameworks": {
"net46": {
}
},
"testRunner": "NUnit"
}
這裏是我運行整個測試:
using MyWebApplication.Controllers;
using NUnit.Framework;
namespace UnitTest
{
[TestFixture]
public class Class1
{
[Test]
public void Test1()
{
Dummy dummy = new Dummy();
}
}
}
這裏是整個類:
namespace MyWebApplication.Controllers
{
public class Dummy
{
public Dummy()
{
}
}
}
最後一個細節,我的Asp.Net核心Web應用程序(.NET框架)4.6參考文獻2其他.NET類庫項目,1是一個實體框架(5.0)項目引用.NET Framework 4.5,第二個是面向.NET Framework 4.6的類庫。