Handling Dependencies from Unmanaged Native to Managed NET, Via C++/CLI

107 views Asked by At

I have two open code bases. The first, where the application starts is in unmanaged C++ (no /clr enabled). The second, that is a dll library, is managed .NET C# (.NET 6) and is opened as a plugin by the unmanaged code

I have complete control over these code bases except for these initial conditions (can't refactor the managed library as a COM object for instance and can't add /clr to the originating native app) I want these two code bases to talk to one another. Additionally with some functions between them operating under time constraints, if that matters (passing video frame data from one to the other in real-time)

In achieving this, so far what we've done is implement a third C++/CLI project as an intermediary (/clr:netcore 6 enabled), that functions really well. We really like this because it works plenty fast for our use case and interop is simple to implement with import/export, entirely inside dev-environment, with full type enforcement throughout

The problem we are having is firing up C# NET from inside C++ results in the app searching around for all of NET's dependencies and failing to find them. And the only way of solving that, that we've found so far is deploying all of NET local to the application's running directory and obviously this isn't ideal

Side note here, we did this by running a publish build on the managed library to collect together all of its dlls. So, on the one hand, we admit we haven't fully confirmed every single dll as required, but we have confirmed - by stepping through adding at least some dlls one by one - that the errors cite various .NET libraries, Accessability, System.Windows.Forms etc. I'm including this just for clarity of what we do and don't know at this point, but we figure that this shouldn't really be relevant because the managed app, when ran as the program entry-point finds all its dependencies as expected and we figure we're missing some kind of setting or hook needed to inform the native/CLI components of how to link into all the managed libraries' references, taking care of everything in one go Please also note that the projects see eachother inside the IDE just fine

Given these initial project conditions, what is the simplest and most direct way to make the native app see the dependencies of the managed app, the same way in which the managed app sees them for itself when ran in isolation?

Ideal candidate solutions should:

  • Be as simple as possible. We're loosely expecting something like a project reference, build parameter or run-time environment variable
  • Introduce as few layers of indirection as possible. There's already one layer via C++/CLI, which is a very transparent layer, with full type enforcement and native IDE integration
  • Happen in-development-environment. Fiddling with O/S path variables isn't really solving the fundamental project visibility issue

Additional context of other interop solutions outside of these lines is fine but won't be accepted as final answers. That would include talk of COM objects, P/Invoke etc. Fine to talk about but would be considered messy and less than the ideal here

0

There are 0 answers