4

I have a .NET 5.0 unit test project that I'm trying to execute via the command line using MSTest.

I'm using a command like the following to run the unit tests:

MSTest.exe /testcontainer:tests\bin\Debug\net5.0\UnitTestProject.dll

But I receive the following error message:

Unable to load the test container 'tests\bin\Debug\net5.0\UnitTestProject.dll' 
or one of its dependencies. Error details: System.IO.FileNotFoundException: 
Could not load file or assembly 'System.Runtime, Version=5.0.0.0, 
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. 
The system cannot find the file specified.

I've seen similar questions on here such as Visual Studio 2017 - Could not load file or assembly 'System.Runtime, Version=4.1.0.0' or one of its dependencies but the answers make reference to editing an app.config file, which I do not have in my project.

Is this just a limitation of using .NET 5.0 and MSTest in the way I'm trying to? Or is there something I can do to allow MSTest to run the tests?

t_warsop
  • 1,170
  • 2
  • 24
  • 38
  • 1
    Do you **have** to use `MSTest.exe` or could you give `dotnet test` a try? – mu88 Jun 24 '21 at 13:31
  • @mu88 so full story ... I need to use a COM library in the project so can't use dotnet test and the docs say to use MSTest instead. I was successfully using dotnet test before the inclusion of said COM library and all was working fine, but ever since it's inclusion I've had a whole heap of problems, this being the last one – t_warsop Jun 24 '21 at 13:44
  • Before .NET Core / .NET 5.0, I'd have recommended to use Fusion Log Viewer to detect assembly binding errors. I don't know whether it still works, but with the old .NET Framework it did a lot good to me. – mu88 Jun 24 '21 at 13:46

1 Answers1

1

So I've done more playing around with this and because I need to use a COM library as part of the project it seems that it's not possible to use .NET 5.0/.NET core stuff in anyway.

I did a test using .NET Framework 4.7.2 - I made a unit test solution using this version of the framework, added a COM library and ran the unit tests at the command line and all worked. The only gotcha with this was I had to use vstest.console.exe and not MSTest to run the tests.

Using MSTest gave me the No tests to execute issue. But it seems like using vstest.console.exe is the answer to this - No tests to execute msTest

t_warsop
  • 1,170
  • 2
  • 24
  • 38