3

Touch confused, so hopefully someone can set me straight.

  • I create a simple .Net Core 2.2 Console app, and then a separate .Net Framework 4.6.2 library project in the same solution.
  • I am actually able to reference the .Net Framework library from the .Net Core App, and use a very simple method from there (e.g. that just returns a string). The app runs fine.

I understood from answers like this that this shouldn't be possible.

Is it that if I were to use any .Net Framework code not native to .Net Core in the console library, then the app would crash at runtime? If this is the case, could someone provide an example of something that would crash the app?

2
  • 1
    Try AppDomain.CreateDomain, which crashes with PlatformNotSupportedException. Which is the nice case, sometimes you'd get MethodNotFoundException etc. Commented Jun 13, 2019 at 15:53
  • @DanielBalas That got it to crash, thanks! Commented Jun 13, 2019 at 16:23

1 Answer 1

3

This works because .NET Core (actually .NET Standard) has compatibility shims that allow for .NET Framework assemblies to be loaded on supported runtimes as long as they only use the supported Types/Methods ("API").

Also see Compatibility shim used by .NET Standard 2.0 and the documentation links in there for more details on the compatibility layer.

Sign up to request clarification or add additional context in comments.

2 Comments

Keep in mind that if you were to ship your app to, say, a Mac or Linux environment, your app won't run, because those dependencies won't install/run on non-Windows machines.
They do, that's the magic of the compatibility shims. So as long as you don't use the registry or .net framework or windows specific features, many things actually work - which is why they created the compatibility shims in the first place

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.