0

In my .NET Framework 4.8 library, in the .csproj file, I have a reference to a .NET Standard 2.0 library, which looks as follows:

<ItemGroup>
    <Reference Include="library">
        <HintPath>..\..\Runtime\netstandard\Release\library.dll</HintPath>
    </Reference>
</ItemGroup>

Everything compiles fine, but during runtime, I get the Exception that the assembly System.IO.Ports or one of it's dependencies could not be found.

My .NET Standard 2.0 library uses the following dependencies (NuGets):

"DotNetZip": "1.16.0",
"NETStandard.Library": "2.0.3",
"System.IO.Ports": "6.0.0",

When I spy on my .NET Standard 2.0 library (library.dll) with ILSpy, I can see that it holds a reference to System.IO.Ports, but still can't find it.

After researching a little I found the following information on this website https://natemcmaster.com/blog/2017/12/21/netcore-primitives/

.NET is a dynamically linked runtime. The compiler adds a reference but does not duplicate its code. The deps.json file is a dependencies manifest. It can be used to configure dynamic linking to assemblies that come from packages.

I'm aware that in the output folder of my .NET Standard 2.0 library there is a library.deps.json and a library.dll.config generated. If I understood correctly from the website, the *.deps.json file should tell the compiler where to dynamically load the packages?

I tried copying the library.deps.json and library.dll.config to the output directory of my .NET Framework 4.8 library, but that did not solve the problem. It still can't find the System.IO.Ports package during runtime. If I target my .NET Standard 2.0 library to net48 I don't get the exception during runtime. What am I missing or doing wrong when targeting netstandard2.0?

How can I tell my .NET Framework 4.8 library to consider the library.deps.json and library.dll.config file so during runtime it knows where to look for this package? Do I have to include these two files somehow in my .csproj of my .NET Framework 4.8?

I couldn't find any information on this online. I appreciate the help!

stgerb
  • 31
  • 5
  • You might need to also add the NuGet package to the project that is the highest-level one that directly or indirectly references the project that actually uses the NuGet package. I.E. if you have an exe that is failing with that error, add the NuGet package to that exe. This is likely to be a workaround rather than the actual solution, though. – Matthew Watson Sep 28 '22 at 13:52
  • 1
    This was the solution to my question: https://stackoverflow.com/questions/49917841/why-the-deps-json-file-on-release-folder-and-publish-output-folder-size-are-d – stgerb Sep 29 '22 at 07:25

0 Answers0