'Net 6 DLL can't load System.Runtime.Caching when called from a /clr:netcore DLL

I have a .Net 6.0 class library (trtDatatypesCore.dll) that uses the package System.Runtime.Caching. The package version is: 6.0.0.

When I call it from a .Net 6.0 console application everything loads and runs fine.

To call this DLL from a cpp executable I created a managed cpp DLL with the following settings:

/clr:netcore Target Framework: net6.0

When it tries to load the trtDatatypesCore.dll I get the following Error:

System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Runtime.Caching, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.'

All of my DLLs are complied and run from a common directory. The package dll is in my user directory.

The trtDatatypesCore.deps.json contains:

"runtimeTarget": {"name": ".NETCoreApp,Version=v6.0","signature": ""},"compilationOptions": {},"targets": {".NETCoreApp,Version=v6.0": {"trtDatatypesCore/1.0.0": {"dependencies": {"Microsoft.Extensions.Caching.Memory": "6.0.0","Microsoft.Win32.Registry": "5.0.0","Newtonsoft.Json": "13.0.1","System.Runtime.Caching": "6.0.0","WinSCP": "5.19.6"},"runtime": {"trtDatatypesCore.dll": {}}},And

  "System.Runtime.Caching/6.0.0": {
    "dependencies": {
      "System.Configuration.ConfigurationManager": "6.0.0"
    },
    "runtime": {
      "lib/net6.0/System.Runtime.Caching.dll": {
        "assemblyVersion": "4.0.0.0",
        "fileVersion": "6.0.21.52210"
      }
    },

I created test console applications (both c++ and NetCore) to test the calling of the c# library to remove the possibility of another version of the DLL being loaded elsewhere.

I verified my Configuration Manager settings are:

Debug: x86 C++ Projects- Platform = WIn32 Core Projects- Platform = Any CPU

Edit: I deleted the package and referenced the DLL directly with the 'copy local' set. The dll was copied into the directory with all the other dlls. Same result.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source