Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can .Net Core Applications use .Net Framework libraries?

Tags:

.net

.net-core

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?

like image 708
John Darvill Avatar asked Nov 24 '25 08:11

John Darvill


1 Answers

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.

like image 68
Martin Ullrich Avatar answered Nov 26 '25 04:11

Martin Ullrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!