1

We have a .Net Framework 4.7 application, that has a dependency on another project in the solution which targets .NET Standard 2.0.

This project again has a dependency on another (external) .NET Standard 2.0 library which has been added through a private Nuget repo. This library depends on Microsoft.Win32 for Registry lookup.

When debugging the .Net FW application, we get a FileNotFoundException during runtime:

System.IO.FileNotFoundException: 'Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.'

I changed the library that uses the Registry and added the Microsoft.Win32.Registry package. When debugging again the error then changed to a different version:

Could not load file or assembly 'Microsoft.Win32.Registry, Version=4.1.3.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

Where do we put the efforts into fixing this? Is something configured wrong in the library that uses Win32.Registry? Or is it the .NET Standard project depending on it? Or in the top layer in the .NET 4.7 application?

sevenam
  • 592
  • 1
  • 8
  • 21
  • I tried option 2 first, where it still crashes on runtime. With option 2 the .NET Framework 4.7 app just exits straight away with code -1. – sevenam Mar 26 '20 at 20:34
  • 1
    when I tested the code from the other user I had no issues. .net framework versions before 4.7.2/4.8 had some issues with .net standard 2.0. so target your app as .net framework 4.8 (which will be last classic 4.x version, version 5 will be .net core based) – magicandre1981 Mar 26 '20 at 20:43
  • I actually got it working now with option 1 after randomly banging my head at the keyboard, cleaning the solution, deleting the packages directory and restarting visual studio. I have no idea which one of those helped, but one of them did. At least it will work until someone cleans the project for nuget packages that apparently aren't in use. Thank you Andre! – sevenam Mar 26 '20 at 21:28

2 Answers2

1

I advise you to right click on the solution, and go to 'manage NuGet packages', then go to the consolidate tab and resolve the conflicts. You probably have various versions of libraries on multiple projects. Usually errors on libraries appear one at a time as you solve them.

alby98
  • 37
  • 4
  • 1
    Even though this didn't solve the problem, thanks for the tip! I've always done this manually before by cross-checking the projects. Never noticed that tab... – sevenam Mar 26 '20 at 19:48
1

For anyone finding the thread, what worked was to add the win32.registry nuget package used by the external library to the .net framework 4.7 project as well.

Even thought this feels far from optimal, it was the only thing that worked in this case, and it'll have to do.

Ref: Why is my .NET framework app looking for the wrong version of the .NET core/standard platform extension assembly, and how do I fix it?

sevenam
  • 592
  • 1
  • 8
  • 21