Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
185 views
in Technique[技术] by (71.8m points)

c# - Compatibility of dynamically loaded assemblies

I want to dynamically load dotnet assemblies at runtime.

Let's say I have netcore 3.1 console app:

  • Can I load .net standard assemblies? If yes what specific version I can load?
  • Can I load classic .net assemblies, like .net framework 4.8? If yes can I also load older versions?

What about reverse situation, when I have dotnet framework 4.8 console app:

  • Can I load .net standard assemblies?
  • Can I load older classic .net, like assemblies,.net framework 4.6?
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

.NET Standard is an interface - a versioned list of APIs that you can call.

.Net standard can be referenced by both .NET framework and .NET core.

What does this mean?

You should use .Net standard for class libraries.

.NET framework and .NET core those two target a platform. .Net framework only works on Windows while .Net core works on all three(Windows/Linux/MacOS) operating systems. These should not reference one another.

This is why .Net standard exists.

So to quickly answer your questions.

  • Can I load .net standard assemblies? If yes what specific version I can load? Yes, you should use .Net standard
  • Can I load classic .net assemblies, like .net framework 4.8? If yes can I also load older versions? You probably can, for sure you should not

What about reverse situation, when I have dotnet framework 4.8 console app:

This is for .NET Standard. Taken from Microsoft Docs.

The documentation is very clear on what you need to pay attention to. The text below is similar to the one in the screenshot. I added here to be more readable.

The following table lists the minimum platform versions that support each .NET Standard version. That means that later versions of a listed platform also support the corresponding .NET Standard version. For example, .NET Core 2.2 supports .NET Standard 2.0 and earlier.

Guide

In addition to this ->https://docs.microsoft.com/en-us/dotnet/standard/net-standard#net-implementation-support

enter image description here

In order to avoid targeting errors and transitive dependencies errors or at least keep them to a minimum. Change your package management to PackageReference when using .NET standard.

<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

The link below provides the full info and also some troubleshooting tips for such errors.

Source: https://www.hanselman.com/blog/ReferencingNETStandardAssembliesFromBothNETCoreAndNETFramework.aspx


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...