question

ScottStewart-9749 avatar image
0 Votes"
ScottStewart-9749 asked DylanZhu-MSFT commented

How do I solve the TypeLoadException Error in unit testing

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.

vs-general
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

DylanZhu-MSFT avatar image
0 Votes"
DylanZhu-MSFT answered ScottStewart-9749 commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thank you, Dylan, for your reply. I did that before I wrote the question. That's my go to answer when weird things happen in VS. This problem began a couple of months ago. Every time I go into the code to add features or do maintenance, I start with writing tests and then remember that the testing doesn't work any more. There is a secret file somewhere that VS is using and there is an incorrect line in the file. I don't know how to make the secret file rewrite itself. I will update this question Monday with more documentation.

0 Votes 0 ·
vb2ae avatar image
0 Votes"
vb2ae answered

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.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

ScottStewart-9749 avatar image
0 Votes"
ScottStewart-9749 answered DylanZhu-MSFT commented

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.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hi @ScottStewart-9749 , maybe you can follow this suggestion, to use procmon.exe tool to detect what the path the test looking for, then copy the dll there.

0 Votes 0 ·