VS2017 Could not load file or assembly Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll or one of its dependencies

29,319

Solution 1

I had a similar issue (with the additional message The "BuildShadowTask" task failed unexpectedly) with a project originally developed with VS2010, and got to spend the last few hours learning about yet another legacy facet of the build process.

There is a good chance that you are dealing with private accessor files (.accessor), which were deprecated in VS2012 (original source). This was foreshadowed in an announcement from the VS2010 team that they were no longer working on these features.

There is also a chance you're just dealing with erroneous refs to the wrong version of UnitTestFramework, but a NuGet restore should fix this. If not, see this GitHub thread for a possible fix (manually change the ref to the public folder), or move to the new MSTest.TestAdapter and MSTest.TestFramework packages (see MSDN support thread).

Solutions

A. Edit the unit test .csproj and change the item Include references from Shadow => None: <Shadow Include="Test References\namespace.accessor" /> to
<None Include="Test References\namespace.accessor" />

B. Better yet, simply delete all the .accessor files from the unit test project's Test References folder.

Ideally, you would also rewrite your unit tests to remove references to private methods, either by re-architecting to separate concerns or by changing properties to internal and using "friend" with the InternalsVisibleToAttribute.


For those who need to continue supporting testing of private methods for some reason, the same post provides the following suggestions to the logical question "What is available for me then?":

For those who wish to continue testing internal APIs, you have three options:

  1. Use the Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject class to assist in accessing internal and private APIs in your code. This is found in the Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll assembly.
  2. Create a reflection framework that would be able to reflect off your code to access internal or private APIs.
  3. If the code you are trying to access is internal, you may be able to access your APIs using the InternalsVisibleToAttribute so your test code can have access to the internal APIs.

However, there is not any good replacement for Code Generation for the new features added by the lanugage teams. You may create the TestMethod stubs and then remove the internal code. You only need to keep the stub itself.


Further reading / sources that helped me piece this together:

Solution 2

Right click the project references folder. Add reference > Assemblies > extensions. Check Microsoft.VisualStudio.QualityTools.UnitTestFramework 10.1, and uncheck any older version.

Share:
29,319
Blake Rivell
Author by

Blake Rivell

I am a .NET developer who builds custom web applications for businesses. I have a very strong passion for what I do. My hobbies are video games and fitness.

Updated on July 29, 2020

Comments

  • Blake Rivell
    Blake Rivell almost 4 years

    When trying to open an older solution in VS2017 there is an old Unit Test project that is giving me a problem when building.

    I keep getting the following error when building this test project:

    Could not load file or assembly 'file:///C:\Projects\MyProj\Test\DAL\UnitTestProj\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll' or one of its dependencies. The system cannot find the file specified.

    I checked the project's references and it appears to be referencing Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll. Additionally there are no code errors. How could I ever figure out if it is one of its dependencies that it can't find?

  • jwill212
    jwill212 over 5 years
    I was having this problem moving my project to a TFS CI build. Removing the "Shadow" node fixed it - thank you sir!
  • Admin
    Admin over 5 years
    Maybe you can clarify why you think this solves the problem in the question, and clarify what steps you think needs to be taken. Note that you can format your examples so it is clear what is explanation and what is a pathname.
  • veljkoz
    veljkoz about 5 years
    There isn't such entry in the Assemblies > Extensions... (in fact, there's none)... where do you find this dll? It can't be added directly through nuget...
  • hyankov
    hyankov almost 5 years
    This is the solution
  • null canvas
    null canvas almost 5 years
    Added the new reference, but I still get "The system cannot find specified file" error
  • Auspex
    Auspex over 3 years
    "Once GAC updated with 10.0.0.0"... If only you'd said how you managed to DO that. My problem is that it's refusing to start a compiled program. I could probably successfully recompile it, but then I couldn't guarantee that it's the same as the old version.
  • Zoomzoom
    Zoomzoom almost 3 years
    Didn't work for me. Had to go with brichin's answer instead. VS 2019.
  • Zoomzoom
    Zoomzoom almost 3 years
    Worked for me. VS 2019.
  • LarryBud
    LarryBud almost 3 years
    For some reason, my install has 3 different "versions", two of which are 10.0, but are located in two different folders in VS2019. One is in "PublicAssemblies", the other is "ReferencedAssemblies". I changed it to "PublicAssemlies" rebuilt, and the DLL appears in the bin file and solved the problem