C++\CLI DLL fails to load framework assemblies for managed assembly

Nauman Hameed 1 Reputation point
2022-12-08T11:45:55.723+00:00

Hi

I have a C++\CLI wrapper DLL which wraps a managed (C#) assembly. The managed assembly is dependent on "Microsoft.AspNetCore.App" framework. The problem is that any assemblies of "Microsoft.AspNetCore.App" used by managed assembly fail to load until they are copied to same folder from where C++\CLI wrapper DLL is loaded. If they are not copied, I get errors like following.

System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.AspNetCore.Hosting.Abstractions, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified.

If I use same managed assembly from another managed assembly, I do not need to copy the "Microsoft.AspNetCore.App" assemblies to local folder.

Copying the DLLs is annoying because we have to copy around 90+ DLLs from "Microsoft.AspNetCore.App" to the local folder of C++\CLI wrapper DLL.

Any way to get around this?

Regards
Nauman

Developer technologies | C++
Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 77,686 Reputation points Volunteer Moderator
    2022-12-09T17:20:54.96+00:00

    the dotnet.exe or the generated core exe has additional code to load assemblies from known locations. You could add support to your code. see:

    https://learn.microsoft.com/en-us/dotnet/core/tutorials/netcore-hosting

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.