2

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?

John Darvill
  • 1,274
  • 11
  • 17

1 Answers1

2

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • 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. – Arash Motamedi Jun 13 '19 at 16:53
  • 1
    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 – Martin Ullrich Jun 13 '19 at 18:07