'Could not load file or assembly' exception when running as a console app

1.2k views Asked by At

I have a new .NET Core 2.0 console app. Whenever I try to add a NuGet package, say Newtonsoft.Json for example I get the following exception when the program is started:

System.IO.FileLoadException: 'Could not load file or assembly 'System.Threading, Version=4.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)'

This somehow happens on System.Console.ReadLine() and when I remove the Newtonsoft.Json package, everything works again. Now, Newtonsoft.Json was just an example, I can add System.Data.SqlClient and the same thing happens. Sometimes a different assembly could not be loaded than the one mentioned in the exception above.

I have included the project. Also, I can easily reproduce this problem as I have countless times created new .NET Core 2.0 console apps to see if my project was corrupt somehow.

My project (last run on Visual Studio Preview): https://ufile.io/yp9xd

Edit 1: I reinstalled Visual Studio 2017 and now I'm only running non-preview. I also reinstalled .NET Core 2.0 and cleared out the NuGet Cache. All this to no prevail. The same result continues to mock me.

Edit 2: I have located the source of the problem. Cross-reference to: https://github.com/JamesNK/Newtonsoft.Json/issues/1423

1

There are 1 answers

0
Daniel Novak On BEST ANSWER

The cause of the issue has been identified. When setting the following configuration to the csproj-file you will encounter my issue.

<BaseIntermediateOutputPath>any-name-except-obj</BaseIntermediateOutputPath>