Could not load file or assembly Visual Studio 2019 (Community)

1

This is going to be one of those questions for which there are hundreds of answers, so please bare with me as I have tried most of them!

I have been breaking up a very large project into smaller components with the view to slowly migrate it all to .NET Core.

Some Projects in my solution are now .NETstandard class libraries, and there are also some .Net Framework (4.7.8) projects.

I was getting on quite well today when suddenly I started getting this:

Could not load file or assembly 'ServiceStack.Text, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)

The version installed in my projects is (was - read on...) 5.8.0.0

Now, I am not new to this error, I've found it before and it usually relates to either a project reference file, web.config or packages.config referencing a .DLL with a different version than that of the file in the /bin directory.

So I have been through all (34) project folders and deleted servicestack.text.dll in every project.

I have uninstalled it via NuGet in every project and reinstalled it.

I have checked every project's packages.config file and where they are .NETStandard projects, the project files and made sure that there are not references to ServiceStack.Text v 5.0.0.0

I have rebuilt, cleaned and restarted the solution, visual studio and my computer many times!

Then I noticed something...

In my .Net Framework projects, under References, if I click on the ServiceStack.Text file and view the Reference Properties, it shows Version: 5.0.0.0, but the Path is directing it at 5.8.0.0.

In the .NETStandard projects, it shows the correct version.

So then I thought maybe 5.9 can't work in the Framework projects, so I uninstalled it from every project and installed v 5.0.0.0 in every project. This then wouldn't build because Visual Studio threw errors in the .NETStandard projects saying "downgrade detected, please restore the updated version"

SO then I installed 5.9 (which is now the latest version) into all the .NETStandard projects, leaving 5.0.0.0 in the .NET Framework ones.

Now it will build, but the FileNotFound exception throws again when I try to run it.

So I have tried;

  • Everything using ServiceStack.Text 5.9
  • Everything using ServiceStack.Text 5.0
  • .NET Framework projects using 5.0 and .NETStandard (2.0) projects using 5.9
  • Uninstalling and reinstalling multiple times
  • Deleting all obj directories, cleaning and rebuilding
  • Checking all project and packages files

Wasted most of the day on this, so turned to SO... I do hope someone can help!

visual-studio
nuget-package
.net-standard
.net-framework-version
servicestack-text
asked on Stack Overflow Jun 22, 2020 by Jamie Hartnoll

1 Answer

1

Right.... Answering my own Question again...

After a lot of messing about I found out what was happening, and it was nothing to do with Visual Studio builds, or .package file conflicts

The reason the error suddenly appeared was a call to Dump() in something I was testing, which had another call to Dump() in a preceding function referencing a different .NET Framework. Whilst according to Microsoft this (mixing Frameworks) works, ServiceStack has different versions and it caused a version conflict.

In case anyone else runs into this, here's what I have found…

Pseudo code example… a function in a .NET Standard Project (2.0)

Function Blah() as Something
 … do something
    Log(TestResult.Dump())
    Return Something
End Function

And then a .NET Framework (4.7.8) Project which consumes this and again tries the Dump the result:

Sub DoSomething()
   Dim Something = Blah()
   Write(Something.Dump())
End Sub

The two frameworks require different versions of ServiceStack.Text and therefore throw a confusing, though I guess correct, FileNotFoundException in the running project.

I’m sure to run into this one again….!

answered on Stack Overflow Jun 23, 2020 by Jamie Hartnoll

User contributions licensed under CC BY-SA 3.0