Ben Croughs
Ben Croughs

Reputation: 2663

Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0'

I am using MSTest.TestAdapter and MSTest.TestFramework both version 1.2.0 for my MS tests unit tests. On my local machine (Visual Studio 2017) the tests run perfectly, but on our build server we get this message:

Could not load file or assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Then I checked the reference of this assembly with ildasm, and indeed it is the 11.0.0.0 version (see below)

However I cannot find the v11 of this assembly, online there is only the v14 version on nuget: https://www.nuget.org/packages/Microsoft.VisualStudio.TestPlatform.ObjectModel/

I also searched on my machine and I couldn't find the v11.

So my question, why does the tests run on my machine and not on the build server?

I tried assembly binding but without success.

enter image description here

Upvotes: 27

Views: 39597

Answers (8)

Ahmed Alejo
Ahmed Alejo

Reputation: 2431

In my case, after upgrading from .NET 5 to 7, it couldn´t load

Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a

The solution is to directly reference MSTest.TestFramework in the test project. Since I was transiently referencing it via a netstandard2.0 class library project.

<PackageReference Include="MSTest.TestFramework" Version="x.x.x" />

version=3.0.02 as of writing

Upvotes: 3

DubMan
DubMan

Reputation: 460

Same problem. Solve by including the adapter locaters in the .proj files:

<PackageReference Include="MSTest.TestAdapter" Version="2.2.10" />
<PackageReference Include="MSTest.TestFramework" Version="2.2.10" />

Upvotes: 1

NeilNewman
NeilNewman

Reputation: 120

In the test output window I had errors like this…

[MSTest][Discovery][C:\Repos\Flomaster\bin\Debug\ApiTest.UnitMaintenance.dll] Failed to discover tests from assembly C:\Repos\Flomaster\bin\Debug\ApiTest.UnitMaintenance.dll. Reason:Type 'Microsoft.VisualStudio.TestPlatform.ObjectModel.Trait' in Assembly 'Microsoft.VisualStudio.TestPlatform.ObjectModel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' is not marked as serializable.

I managed to get my test runners working by Cleaning out all my obj and bin\debug folders, but it came back so I looked a bit deeper and found that just searching for Microsoft.VisualStudio.TestPlatform.ObjectModel.dll and removing any matching files was enough to get the test runner working

Upvotes: 3

Hermann.Gruber
Hermann.Gruber

Reputation: 1494

Other workarounds are recommended here

Don't reflect types from "Microsoft.VisualStudio.TestPlatform.ObjectModel" assembly. OR Downgrading Microsoft.NET.Test.Sdk to 15.3.0.

Probably the second option does not apply for you since you are on .NET framework and not .NET core.

More background:

Upvotes: 4

Chad Lehman
Chad Lehman

Reputation: 952

Faced the same error after having mistakenly added the NuGet package for NUnit 3.0 to several projects in the solution and then removing it.

The reference didn't get removed completely. I had to open each .csproj file manually and delete all references to the previously removed NuGet package. After a clean and rebuild, the error went away.

Upvotes: 1

DoubleJ
DoubleJ

Reputation: 569

Same issue, I was able to install the latest version:

Install-Package Microsoft.TestPlatform.ObjectModel -Version 15.8.0

Then add a binding redirect to the test projects app.config:

    <runtime>
        <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
            <dependentAssembly>
                <assemblyIdentity name="Microsoft.VisualStudio.TestPlatform.ObjectModel" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
                <bindingRedirect oldVersion="11.0.0.0-14.0.0.0" newVersion="15.0.0.0" />
            </dependentAssembly>
        </assemblyBinding>
    </runtime>

Upvotes: 7

Ben Croughs
Ben Croughs

Reputation: 2663

after facing the same issue again in another project, we looked at it again and found a solution.

Install-Package Microsoft.TestPlatform.ObjectModel -Version 11.0.0

But this was not enough, to make sure the assembly was picked up by the build server, we added it as a deployment item to the base test class;

[DeploymentItem("Microsoft.VisualStudio.TestPlatform.ObjectModel.dll")]

And now the build server is again picking up the unit tests :-)

Grtz

Upvotes: 2

Logan Engelberth
Logan Engelberth

Reputation: 161

The NuGet package you want is Microsoft.TestPlatform.ObjectModel authored by Microsoft, not the Microsoft.VisualStudio.TestPlatform.ObjectModel package authored by Christopher.Haws.

https://www.nuget.org/packages/microsoft.testplatform.objectmodel/

The Microsoft package has Microsoft.VisualStudio.TestPlatform.ObjectModel assemblies in it, despite it not being named that way. I was getting the same error and when I installed v11 of the Microsoft package it fixed the build on the build server for me.

Upvotes: 16

Related Questions