Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MS Test "Method not found: System.String" Error

Since recently some of my MS Test unit tests have stopped working. I haven't changed anything in the tests themselves. The error I am getting is the following:

Test Failed - [file name]

Message: Method not found: 'System.String Microsoft.VisualStudio.TestTools.UnitTesting.TestResult.get_TestContextMessages()'.

Under 'References', in my unit test Project (in Visual Studio), I have the following:

Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter

Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices

Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.Interface

Microsoft.VisualStudio.TestPlatform.TestFramework

Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions

Moq

Ploeh.AutoFixture

Ploeh.AutoFixture.AutoMoq

Anybody know what the problem is here?

like image 781
lukegf Avatar asked Jan 31 '23 00:01

lukegf


2 Answers

So the problem essentially is what I described in the last comment, i.e. if you create a new Unit Test project in Visual Studio 2015, it comes with Microsoft.VisualStudio.QualityTools.UnitTestFramework already installed. If you then install MSTest.TestFramework from NuGet, which is going to be MSTest version 2 (this is important to note), this is going to create Ambiguous Reference issue for test attributes such as TestClass and TestInitialize, i.e. the Unit Test project doesn't compile.

To resolve the issue above, the Microsoft.VisualStudio.QualityTools.UnitTestFramework reference can be removed from the project. That makes everything work fine, which was the case with my project. After some time though, for an unknown reason, something got corrupted in my Unit Test project and I started getting the error in the original post. To resolve this, I created a new Unit Test project, moved all of my unit tests to it, added a reference MSTest.TestFramework and deleted the one to Microsoft.VisualStudio.QualityTools.UnitTestFramework.

Here is a related issue.

like image 125
lukegf Avatar answered Feb 08 '23 06:02

lukegf


Have you also referenced Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll? I don't see it in mentioned project references. This library is referenced in MS test projects by default though.

Also, see if the processor architecture of the tests and target project are same. Processor architecture of the test can be checked from menu Test->Test Settings->Default Processor Architecture. Possibly it would need to be changed to x64.

like image 27
DiligentKarma Avatar answered Feb 08 '23 05:02

DiligentKarma