How do I solve the TypeLoadException Error in unit testing

Scott Stewart 1 Reputation point
2021-03-30T14:45:32.63+00:00

Windows 10 Pro
Visual Studio Enterprise 2019 V 16.8.4

I am getting an error when trying to run a unit test. It says System.TypeLoadException: Could not load type 'Parsers.FileOps' from assembly 'Parsers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. Parsers is in the Referenced project Parsers. The initial problem is that it is version 2.4.0.0 not 1.0.0.0. But I can't find the place where the version is set.

I tried to reference the problem here and in other forums. The answers are years old, different versions of VS or just don't answer the issue at all. References to GAC and other things without the information required to find these files.

This had been working fine. I have written 69 tests and they have all run at least once. No I cannot share the project.

Thank you for looking at this. Thank you even more for replying.

Visual Studio
Visual Studio
A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.
4,602 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Dylan Zhu-MSFT 6,406 Reputation points
    2021-03-31T04:46:09.863+00:00

    Hi ScottStewart,

    You can try to re-load the project in solution explorer, then clean > rebuild your project.

    Best Regards,
    Dylan


    If the answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our **documentation to enable e-mail notifications if you want to receive the related email notification for this thread.**


  2. Ken Tucker 5,846 Reputation points
    2021-04-04T00:49:17.017+00:00

    Couple of suggestions. Make sure the unit test project is referencing the project and not the compiled dll. Check that the .net framework version of the unit test project is the same or higher than the parsers project.

    0 comments No comments

  3. Scott Stewart 1 Reputation point
    2021-04-05T15:22:38.387+00:00

    I followed vb2ae's reply, thank you, to see what would happen. Just to make sure, I removed the reference and then re-added it. It is definitely pointing to the project. No change.

    I try to keep the proprietary stuff from my questions and I think I create more problems that way. Let me try to clarify some things starting with the error.
    Could not load type 'ProjName.FileName' from assembly 'ProjName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
    The file "FileName." is in the project and the reference points to the project. The test module Imports the project, but no the folder the FileName is in. The name of the folder has a space in it and it is not handled the same way that C# handles it. The program runs and there is no problem running the methods called in that particular file.

    I get the same error regardless of the test I run. The only difference is the FileName.

    I have updated all the Nuget packages. I have a perfectly clean build. I have unloaded and reloaded the Test project. I have cleaned and rebuilt the projects.
    Thank you all.