I'm trying to run an NUnit case. When I load the library, I get the following message
System.BadImageFormatException : Could not load file or assembly ... or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
You may be attempting to load an assembly built with a later version of the CLR than the version under which NUnit is currently running, 2.5.5.0727.
I've searched everywhere to find out what is causing this problem. I found another post that mentioned changing in the config file to the current .NET version that is installed. I did that and I am still getting the same error.
I'm currently using NUnit 2.4.8 and the latest version of Selenium 2.0. Any thoughts on this?
EDIT - I've noticed a lot of people are running in to this issue when using the x64 exe when they should be using x86. My library was compiled with an x86 install of Visual C# Express and I'm using the x86 NUnit executable.
Which version of the framework have the unit tests been build against? Old version of NUnit (< 2.5.6) have issues with unit tests build against the .NET 4 framework. If you building against the .NET 4 framework then I would highly suggest upgrading to the latest NUnit both to run your tests, and build against.
Related
I'm trying to run some unit tests on a .NET project (not .NET Core). Visual Studio Code is able to recognize the project, intellisense works and it even offers the links to run and debug unit tests:
The problem is that clicking the unit test does not work. It gives the following error:
Build FAILED.
/usr/local/share/dotnet/sdk/1.0.4/Microsoft.Common.CurrentVersion.targets(1111,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.6.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend.
My guess is that it's trying to use the .NET Core MSBuild, but this is not a .NET Core project.
If I use mono's msbuild from the command line, the project builds. I'm also able to run the unit tests from the command line using NUnit's runner (from the NuGet package).
Do you know if it is possible to configure Visual Studio Code, on a Mac, so that it can run unit tests on a .NET project?
Info about my setup:
Resharper 2016.3.2
XUnit 2.2.0
VS 2017 RTM
Test Project .net 4.5.2
Asp.net Core Project .net 4.5.2
Repo Steps:
Create an asp.net core site targeting .net 4.5.2
Add a unit test project or class library to the solution and reference the asp.net project
Create a xunit Fact test that targets a class in the asp.net project
Run the unit test using resharper test runner
Error:
System.BadImageFormatException
Could not load file or assembly 'AFAEMS, 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.
at AFAEMS.Tests.Class1.return_errors_if_missing_fields()
Notes:
I've done a lot of searching and cannot find any similar issues to this. I can run a unit test with a simple assert that is not targeting the asp.net core class files. I couldn't get the VS test runner to find my xunit tests (maybe b/c resharper test runner is enabled?).
These were things I found but don't indicate how to fix with the new xproj and app.config using MSBuild for VS 2017.
https://blogs.msdn.microsoft.com/visualstudioalm/2016/05/30/announcing-mstest-framework-support-for-net-core-rc2-asp-net-core-rc2/
Testing Asp.Net Core on full .NET framework
https://github.com/dotnet/sdk/issues/926
In Visual Studio change the target from “X86 ” to “Any CPU”.
Also,you will get this error if you try to host an application with a 32-bit assembly reference ,on IIS running on a 64 bit server/machine. To fix this error set "Enable 32 bit applications" flag to true in Advanced settings of the application pool hosting the application in IIS.
I was able to get this fixed by using the following settings in my Resharper unit testing options.
After upgrading our project to .net 4.6.1, some of the unit test written for MEF Open Generics turned red when they are run using mstest.exe that shipped with visual studio 2015. After further investigation I found that the Open Generics types are not getting registered in the mef catalog. Same test used run fine with vs2015 mstest before upgrading projects to .net 4.6.1.
The problem is only with mstest.exe. The same test runs fine if I run them using visual studio test. runner(vstest.console.exe). Alsohe Open Generics types are properly registered when application is launched.
I tried using .runsettings file with Framework45 value and the tests run green. When TargetFrameworkVersion is not specified I believe the mstest is falling back to .net 40 where mef open generics were not supported.
the .runsettings file was not needed when projects were on 4.5. It seems there is some issue with mstest.exe shipped with vs2015. I tried vs2015 update 3 and the issue still exists. Does anyone know work around other than using .runsettings
I am working on upgrading my .NET solution from 3.5 to 4.6.1. For this I have used VS 2015 to do the changes and compilation is almost going through fine. However, one of the projects in my solution is failing with the below error while compiling --
D:/build/toolchain\Win32\winsdk-6.1.6000\bin\svcutil.exe /serviceName:Sim.WebService.SimServer d:\build\SimServer\webservice\SviWebService.exe
.....
Could not load file or assembly 'file:///d:\build\SimServer\webservice\SviWebService.exe' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.
I think this is because the SviWebService.exe is generated using .NET 4.6.1 and we are executing the svcutil on this exe from an earlier version of winsdk, which is 6.1.6000 as seen above. I wanted to verify this by using svcutil from a newer version of winsdk like 8.0 but cannot do this because of some external dependencies. But can some confirm if my guess is correct. Basically, is .NET 4.6.1 compatible with older version of winsdk like 6.1.600
I suspect this is the case, and While I can't confirm this is the case, you should be able to test this yourself fairly easily - as you've installed Visual Studio 2015, I would expect to find the correct version in C:\Program Files (x86)\Microsoft SDKs\Windows\v10.0A\bin\NETFX 4.6.1 Tools\SvcUtil.exe
Try running that version to register your service - if it works then you'll know for sure that it's a compatibility issue.
I an earlier thread I got some help to track down a deprecated .Net assembly reference and I was successfully able to port my project to build within Visual Studio 2010.
Is there any option to get this ReportViewer to work within Mono? Building the project with MonoDevelp 2.2.2 currently gives me similar errors:
Assembly "Microsoft.ReportViewer.Common Version=8.0.0 [...] not found
Assembly "Microsoft.ReportViewer.WinForms [...] not found
Thanks for all help :)
Try running all of the dependent assemblies through the Mono Migration Analyser. It currently targets Mono 2.6, but 2.8 has recently been released.
If the assemblies pass the tests in that then they'll work fine in Mono. If they don't pass the tests then there's a slim chance that they'll work, it just depends which functionality is used.