Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to resolve System.Windows.Forms.dll in .Net Core 3.1

I have a scenario where we are using a legacy .Net Framework dll in .Net core 3.1 class library. Internally .Net Framework dll is using System.Windows.Forms.dll which .Net core is not able to resolve.

I am getting below error message during runtime

Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. The system cannot find the file specified.

In a ideal world there is no point in adding System.Windows.Forms.dll to a class library but is there any way to add System.Windows.Forms and its dependencies in .Net core class library.

Note: I have tried manually adding System.Windows.Forms.dll but it did not work out.

like image 426
Baala Srinivas K Avatar asked Jan 24 '20 04:01

Baala Srinivas K


2 Answers

I got the resolution, we can achieve this by framework reference.

<FrameworkReference Include="Microsoft.WindowsDesktop.App" /> 

For more details please refer https://natemcmaster.com/blog/2019/01/09/netcore-primitives-3/

like image 165
Baala Srinivas K Avatar answered Oct 05 '22 18:10

Baala Srinivas K


It works with me in .net core 3.1 by adding <UseWindowsForms>True</UseWindowsForms> inside project .csproj file to become like this:

<PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <UseWindowsForms>True</UseWindowsForms>
</PropertyGroup>
like image 29
Hosam.Yousof Avatar answered Oct 05 '22 19:10

Hosam.Yousof