我有一个.Net核心API项目。它必须为.Net框架使用一些第三方库(与net47不兼容),因此我们在.csproj中将TargetFramework属性从"netcoreapp2.0“更改为"net47":
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<!-- <TargetFramework>netcoreapp2.0</TargetFramework> -->
<TargetFramework>net47</TargetFramework>
<RuntimeIdentifier>win7-x64</RuntimeIdentifier>Everything is working fine apart from the fact that I'm not able to create test projects on this.
I like to use NUnit.
I tried to create .net core test project (using both MS Unit Test and XUnit) but them are both unable to run the test.
"Run test" is simply ignored.
I created also a .Net Framework test project and in this case I have an error at runtime when the test try to use some classes from the "fake" .Net Core project.
The error is this:
> Message: System.BadImageFormatException : Could not load file or assembly 'MyCompany.ProjectA.Api, 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.
>
Another developer that use ReSharper can run the test created with .Net Core without any problem.
It is discovered (using ReSharper) and it can be debugged.
Please do not suggest me to NOT use "net47" in the project file. It is not an option.
Additional info.
The test project is loading the correct packages:
```javascriptsame problem (test dot discovered or ignored on "run") adding these:
```javascriptWhen the test is ignored the error in the console is this:
```javascript19/02/2018 16:01:28警告异常System.InvalidOperationException,在System.InvalidOperationException中抛出异常执行测试
19/02/2018 16:01:28由于对象的当前状态,警告操作无效。
19/02/2018 16:01:28在Mono.Cecil.ModuleDefinition.ProcessDebugHeader()警告
在Mono.Cecil.ModuleDefinition.ReadSymbols(ISymbolReader阅读器)
在Mono.Cecil.ModuleReader.ReadSymbols(ModuleDefinition模块中,ReaderParameters参数)
在Mono.Cecil.ModuleReader.CreateModuleFrom(Image图像上,ReaderParameters参数)
在Mono.Cecil.ModuleDefinition.ReadModule(流,ReaderParameters参数)
在Mono.Cecil.ModuleDefinition.ReadModule(String fileName,ReaderParameters参数)
在NUnit.VisualStudio.TestAdapter.NavigationDataProvider.CacheNewTypes(String assemblyPath,IDictionary`2 `2类型)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 103中
在NUnit.VisualStudio.TestAdapter.NavigationDataProvider.GetNavigationData(String className,String methodName)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NavigationDataProvider.cs:line 48中
在NUnit.VisualStudio.TestAdapter.TestConverter.MakeTestCaseFromXmlNode(XmlNode testNode) ( C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 144 )
在NUnit.VisualStudio.TestAdapter.TestConverter.ConvertTestCase(XmlNode testNode)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\TestConverter.cs:line 79
在NUnit.VisualStudio.TestAdapter.NUnit3TestExecutor.RunAssembly(String assemblyPath,TestFilter filter)在C:\Users\Terje\Source\Repos\nunit\nunit3-vs-adapter\src\NUnitTestAdapter\NUnit3TestExecutor.cs:line 249中
**[Solution]**
I've removed the [RID](https://learn.microsoft.com/en-us/dotnet/core/rid-catalog) from the API project and the is found and run.
```javascriptwin7 7-x64
我试图将它更改为"win-x86“,或者将测试项目从非选择(=任何CPU)更改为x86或x64。
所有这些都不是一个好的解决办法。
发布于 2018-02-19 16:05:17
我认为你遇到了32位/64位的冲突,你可以看到这样的答案:无法加载文件或程序集.尝试加载格式不正确的程序(System.BadImageFormatException)。
https://stackoverflow.com/questions/48869785
复制相似问题