Can I use a .net 5 library with a .net 6 application?

Viewed 1038

I have an application that we are going to upgrade from .net framework 4.6 to .net 6. However one class library has to be run in .net 5 because of limitations in a Linux version that we have to use. So I wonder if it is possible to use the .net 5 library with .net 6?

1 Answers

I tested experimentally on a simple case. The .NET6 app referencing .NET5 library could be built without any warnings or errors and ran without runtime problems:

Referencing a .NET5 library from a .NET6 app

Some related quotes from Microsoft Docs:

If you're using libraries to break down an application into several components, we recommend you target net5.0 or net6.0. For simplicity, it's best to keep all projects that make up your application on the same version of .NET. Then you can assume the same BCL features everywhere. (...)

To me, this sounds like a good practice to have everything on the same version (5 or 6), but not like a strong requirement.

I'm not 100% confident about edge cases, however. I couldn't find any confirmation of compatibility. At the moment, I would hesitate running a complex production app built from components mixing 5 and 6.

Related