0

Is it possible to use a .NET C++/CLI DLL from a .NET Core 2 application on Windows?

I have a DLL built with <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>. From a .NET Core test app, I do:

Assembly.LoadFrom("mycliassembly.dll");

And I receive this exception:

Could not load file or assembly ... Format of the executable (.exe) or library (.dll) is invalid.

So the obvious answer would be no. But.. is there a way, assuming we are talking about Windows only?

richb
  • 4,716
  • 5
  • 24
  • 22
  • https://stackoverflow.com/questions/39140014/c-cli-support-in-net-core , https://github.com/dotnet/corefx/issues/24444 (not strictly C++/CLI, but P/Invoke and wrappers usable). Also, just target .NET Framework via .NET Standard..? – user2864740 Jun 28 '18 at 01:05
  • It is a duplicate but I think this this question is phrased more simply and the answer about using net461 might be helpful to others. – richb Jul 05 '18 at 12:06

1 Answers1

1

Alright according to the linked question, the best answer is from [https://stackoverflow.com/a/40239864/283467]:

"As far as I know there is no plan to support C++/CLI with .NET Core."

So the solution is don't use .NET Core. Instead, since it's Windows only, use:

<TargetFramework>net461</TargetFramework>

Hopefully Microsoft will continue to support ASP.NET Core on .NET Framework.

richb
  • 4,716
  • 5
  • 24
  • 22