Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 541
Ben Croughs Avatar asked Nov 07 '17 10:11

Ben Croughs


3 Answers

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:

  • https://github.com/nunit/nunit3-vs-adapter/issues/388
  • https://github.com/microsoft/vstest/issues/1098
like image 199
Hermann.Gruber Avatar answered Nov 15 '22 02:11

Hermann.Gruber


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.

like image 24
Logan Engelberth Avatar answered Nov 15 '22 01:11

Logan Engelberth


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>
like image 6
DoubleJ Avatar answered Nov 15 '22 01:11

DoubleJ