What I am trying to achieve?
Use System.Text.Json in my VSTO Addin, which has worked recently but stopped to work when I upgraded RestSharp
What is the problem?
2 Exceptions while running the VSTO Plugin in Debug Mode in Outlook: First:
FileNotFoundException: Die Datei oder Assembly "System.Text.Json, Version=8.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
Second: FileNotFoundException: Die Datei oder Assembly "System.Text.Json, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abhängigkeit davon wurde nicht gefunden. Das System kann die angegebene Datei nicht finden.
So in short: Neither version of System.Text.Json can be found. 8.0.0.2 and 7.0.0.2
My setup:
Visual Studio 2022 with latest updates. Project setting:
And yes I realized that 7.0.2 != 7.0.0.2
This is how Nu Packages admin for the Project looks like when I hit:
and yes I already tried to upgrade to 8.0.2 but this delivered the same result by:
still the same problem
What I also already tried:
I changed my target framework and found the hint that changing the target framework may influence the installed packages (this is the link provided my VisualStudio 2022: https://learn.microsoft.com/en-us/nuget/consume-packages/reinstalling-and-updating-packages) . Thus I remove RestSharp and System.Text.Json. Then searched for RestSharp, found out that it in the current stable version 110.2.0 depends on at least .Net Framework 4.7.1. Thus I switched to .Net Tartgetframework 4.7.1 in my project setting like this:
Then added RestSharp. Which my itself installed System.Text.Json 7.0.2
The exception still stays the same:
Exception 1:
FileLoadException: Die Datei oder Assembly "System.Text.Json, Version=8.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
Exception 2:
FileLoadException: Die Datei oder Assembly "System.Text.Json, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" oder eine Abhängigkeit davon wurde nicht gefunden. Die gefundene Manifestdefinition der Assembly stimmt nicht mit dem Assemblyverweis überein. (Ausnahme von HRESULT: 0x80131040)
At least it is a minor improvement as the error message changed from: File not found to The manifest definition of the assembly found does not match the assembly reference. (Exception from HRESULT: 0x80131040)
What I still don't get is that RestSharp depends in 7.0.2 but the Exception tries to find 7.0.0.2. Please note 7.0.0.2 != 7.0.2 is it?
So i investigated my Project csproj file:
and found for RestSharp:
<Reference Include="RestSharp, Version=110.2.0.0, Culture=neutral, PublicKeyToken=598062e77f915f75, processorArchitecture=MSIL">
<HintPath>..\packages\RestSharp.110.2.0\lib\net471\RestSharp.dll</HintPath>
</Reference>
and for System.Text.Json:
<Reference Include="System.Text.Json, Version=7.0.0.2, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Text.Json.7.0.2\lib\net462\System.Text.Json.dll</HintPath>
</Reference>
--> Question: Is that correct?
I investigated whether there is the dll available:

The answer is yes?
On stack overflow: Could not load file or assembly 'System.text.json' , version 4.0.1.0
--> Question What do I need to check this?
https://www.nuget.org/packages/Microsoft.Extensions.Configuration.Json/#dependencies-body-tab
--> I use 4.8.1







I just realized that there are two different options how to administer your NuPacket.
1.) Solution
2.) Project
After updating the information on the solution layer everything works like charm.
In detail:
Other than the same thing on the project layout VisualStudio now indicates that 2 packages were outdated and needed update
On the tab "Installed" I just needed to hit Update / Install