-1

I am currently working with a new C# .NET 5 Blazor Project. As we "upgraded" our Application from an .NET 4 Framework (new project using old code) I am currently running into one issue i am not able find any solution.

The issue: I wrote code using a 3rd party assembly. This 3rd Party assembly with the latest version to get is targeting .NET 4.8. Now this 3rd Party assembly is throwing exceptions due to accessing parts of the AppDomain which are not present anymore in the .NET 5 Framework (AppDomain.CurrentDomain.SetupInformation.ConfigurationFile). As microsoft removed or changed the way of how AppDomains are used now in .NET 5.

Now my question is. Is there any way to get the 3rd party assembly still loaded that it targets and uses the .NET Framework 4.8 instead of the main projects .NET 5 Framework ? Tho that I am still able to use it (no exception should be thrown as the AppDomain code is present in the .NET 4.x), without having to wait for the company to adapt the assembly to support .NET 5 ?

I tried using the "AssemblyLoadContext" but had no success till now.

Thank You for any Information or Help! Stay Safe!

  • Check https://stackoverflow.com/questions/56027997/can-i-add-a-reference-to-a-net-framework-dll-from-a-net-5-project#:~:text=NET%20Core%202.0%20Microsoft%20implemented,5%2C%20you're%20safe. – Dave May 06 '21 at 13:46
  • 1
    There's no `.NET 5 Framework`. .NET 5 is .NET *Core* 5. You simply can't use .NET Old assemblies. As for .NET Framework 2.0, that's a different runtime from even .NET Framework 4. There are compatibility issues using .NET 2.0 assemblies in .NET 4 – Panagiotis Kanavos May 06 '21 at 13:46
  • It depends which 3rd-party assembly. If you have the source code, you can compile with .NET Core with possible modification. – Frank May 06 '21 at 13:48
  • Hi, nah i only have the compiled assembly tho i am not able to recompile it to target .NET Core. Ok thats what i already thought it wont actually work. Thanks for you input! – rootjumper May 06 '21 at 14:03
  • New version of Net are self contained and you only need to install one version of Net. Older version of Net like 4.0 you need to install Net 1.0,2.0,3.0,3.5 and 4.0. If your project is still referencing older versions of Net than either you have to rebuild with newer version of Net (clean build) or install the older version of Net. – jdweng May 06 '21 at 14:21

1 Answers1

0

Unless otherwise specified, new major versions of .Net should be presumed to be incompatible with older versions. However, there seem to be quite a few exceptions to this rule.

  • .Net 4 could usually load .Net 3.x assemblies just fine
  • .Net 5 is as far as I can tell mostly backward compatible with .Net core 3

The change from .Net framework 4.8 to .Net core and .Net 5 have been quite significant. While there have been quite a bit of work to make the transition smoothly, there are some features that have simply been removed from .Net 5:

There are some technologies that will remain .NET Framework specific, such as AppDomains, Remoting, etc, WCF Server and WWF.

Source: .net 5 backward compatiblity with .net framework?

The solution should be to Update any third party libraries to versions targeting .net standard, .net core or .Net 5. Most of the popular libraries seem to have been updated already.

If this is not possible you might want to consider to politely request libraries to be updated by the author, or update the libraries yourself in case they are open source.

As last resort you might want to replace the libraries with something else that do support the newest .Net versions.

JonasH
  • 28,608
  • 2
  • 10
  • 23
  • Hey Bud, ty for your response! As you already mentioned e.g. the AppDomain is not present anymore like it was used to be in older versions. And as the 3rd Party Assembly does not provide any sourcecode i can only downgrade my project or hope they will update their assembly to support .NET 5. Thanks again for your help! – rootjumper May 06 '21 at 15:02