'C++/CLI project in C# solution usage

Maybe this header isn't decribe my problem exactly, but... I have .NET Core console app project which uses C++/CLI project written as a wrapper for native C++ code from same dll. So, both C# and C++/CLI project are compiled well, but when I run C# project, I get this error:

Could not load file or assembly 'Microsoft.VisualC.STLCLR, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'. The system cannot find the file specified.

I checked this file on my disk - I have it installed in many directories on it. I wrote all paths I've found in the PATH enviroment variable, but no effect.

My configuration: Windows Server 2016, .NET Core 3.1.102, MSVS 2019 16.4.3.

Please, can someone say me the reason of this error and give me a correct solution? Thnxs. P.S. IF it needs I can add classes and data I use in my code.

P.P.S. I have it works under .NET Framework 4.8, but not .NET Core 3.1



Solution 1:[1]

I downloaded Microsoft.VisualC.STLCLR dll from C:\Windows\Microsoft.NET\assembly\GAC_MSIL and I put it on my repository and references it on my .net core project it works.

Solution 2:[2]

I am having the same error while migrating from .NET Framework 4.8 to .NET 6. I tried to copy the dll side by side with my binaries but with no success. Procmon did not even list any read of the DLL (I am an happy user of Procmon for many years).

To bypass the runtime error, I removed uses of the cliext namespace in our C++/CLI code. In my case, I had to convert code depending on :

#include <cliext\set>
#include <cliext\functional>
#include <cliext\vector>
#include <cliext\algorithm>

The exception occured after a call to a method which was using one of the cliext container.

By chance, the amount of conversion work was minimal.

Sources

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

Source: Stack Overflow

Solution Source
Solution 1 abmptit
Solution 2 Benoit Andrieu