Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will mixed mode assemblies (C++/CLI projects) work on .NET Core?

I have a code base that uses a C++/CLI project which exposes C++ classes to the CLR via thin wrapper classes. For example...

C++ code in a C++ project

class Foo {
    public Foo(bool wat) { /* do the things */ }
};

C++/CLI code in a mixed-mode assembly (C++/CLI project)

public ref class ManagedFoo {
    Foo * foo;
public:
    ManagedFoo (bool wat) { foo = new Foo(wat); }
    !ManagedFoo () { delete foo; }
    ~ManagedFoo () { this->!ManagedFoo (); }
};

As far as I know, mixed-mode assemblies will pretty much only run on Windows .NET. I'm hoping I don't need to re-factor the components and use P/Invoke, which would give me cross-platform support.

Does anyone know if .NET Core will support mixed mode assemblies? Other ideas are welcome.

like image 293
Nick Strupat Avatar asked Apr 09 '15 17:04

Nick Strupat


People also ask

Is C++ CLI cross platform?

C++/CLI support is Windows only, even when running on . NET Core. If you need interoperability cross-platform, use platform invokes. C++/CLI projects cannot target .

Does .NET core support C++?

NET Core 3.1 and Visual Studio 2019, C++/CLI projects can target . NET Core. This support makes it possible to port Windows desktop applications with C++/CLI interop layers to .

What is mixed mode assembly?

Mixed mode means that the assembly can run managed and unmanaged code.

What is Ijwhost DLL?

NET Core, ijwhost was created as a shim for finding and loading the runtime. All C++/CLI libraries are linked to this shim, such that ijwhost. dll is found/loaded when the C++/CLI library is loaded. By default, Windows' DLL search will look for dependencies of a DLL as if they were loaded with just the module name.


2 Answers

Unmanaged code in context of C++/CLI is always platform specific and is compiled for a specific OS (Windows) and specific CPU architecture (x86/x64). Unmanaged code in C++/CLI ends up being much like actual C++ code compiled using a C++ compiler. Since mixed mode assemblies can contain native code, they are bound to a specific OS and CPU architecture.

EDIT (March 2019): This answer predates .Net Core and may be out of date in Core context.

like image 62
Matěj Zábský Avatar answered Oct 10 '22 13:10

Matěj Zábský


Whether or not a mixed mode assembly works with .NET Core is not determined by platform specific code. Support for mixed mode assemblies is being worked on in:

https://github.com/dotnet/coreclr/issues/18013

As far as I understand this will require recompiling C++/CLI projects to target .NET Core.

Of course, a mixed mode assembly with x86 code for Windows will only work as x86 in Windows and so on.

like image 33
nietras Avatar answered Oct 10 '22 14:10

nietras