8

We have .NET 6 Blazor Server-side project in Visual Studio 2022. We would like to use .Net Framework 4.8 class library in .NET 6. In this class library, we are using System.Windows.Form and we cannot recompile the class library with .NET Standard 2.0.

I have added .Net Framework 4.8 class library project as dependency for Blazor Application. I am able to compile the solution but when try to run the Blazor Application then it complaints with "System.IO.FileNotFoundException: 'Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.".

We would just like to run Blazor project in windows only.

Jay Vansjalia
  • 83
  • 1
  • 6
  • 3
    Short answer: you can't. – Martin Costello Jan 31 '22 at 09:38
  • 4
    .NET 6 and .NET Framework 4.8 are no interoperable. You will have to migrate and recompile the 4.8 library to either .NET 6 or .NET Standard. – Aleksander Stukov Jan 31 '22 at 09:41
  • Does this answer your question? [Can I add a reference to a .NET Framework DLL from a .NET 6 project?](https://stackoverflow.com/questions/70005465/can-i-add-a-reference-to-a-net-framework-dll-from-a-net-6-project) – Darkproduct Sep 21 '22 at 14:41
  • 1
    Contrary to the comments and to my surprise, I can create a new core app inside my old solution, and access my old .net framework libraries in that same solution... So I am accessing my 4.8 libraries from a .NET 6 console app... – BTC Nov 08 '22 at 16:03
  • 1
    Same here, same surprise. I created a .NET 7 webapi project, reference a framework 4.8 project. Just works... ¯\_(ツ)_/¯ – Joep Geevers Feb 01 '23 at 08:11
  • @LDW Did you ever find out more about the topic? I'm generally also saying that NET targetting NET Framework shouldn't work, but we have one construct, where this is done. Is it probably just a check from Microsoft in Visual Studio, which is missing? – Matthias Müller Feb 15 '23 at 07:39
  • No, I’d love to know more and why it works when the general consensus is that it shouldn’t work… I have only tried this for testing purposes, not for anything in production. Maybe @JoepGeevers knows more? It’s certainly one of my more “mysterious” .net experiences… – BTC Feb 16 '23 at 09:15
  • I was trying to solve the same issue, but I also always received FileNotFoundExceptions for referenced .Net48 assemblies. However I found out that when I explicitely loaded the .Net48 assembly via Assembly.LoadFrom(..) it was working. I now use the AppDomain.CurrentDomain.AssemblyResolve event and load in the handler manually these Assemblies via Assembly.LoadFrom() – ChrisG Jun 28 '23 at 14:34

0 Answers0