question

Prabs-7622 avatar image
0 Votes"
Prabs-7622 asked karenpayneoregon answered

Can I use .NET framework DLL in .NET core?

Hello All,
I have an .Net Core console application. Can I use .NET framework DLL in .NET core?
Please help me on this

dotnet-csharpdotnet-runtimedotnet-runtime-frameworkdotnet-runtime-core
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Castorix31 avatar image
1 Vote"
Castorix31 answered

Normally, no.
But there is the Windows Compatibility Pack for .NET Core


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Prabs-7622 avatar image
0 Votes"
Prabs-7622 answered

I tried now.it is working. I have created some sample .Net framework dll and added into .Net Core project.

5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

karenpayneoregon avatar image
0 Votes"
karenpayneoregon answered

You should consider taking the .NET Framework code and migrating to .NET Core. Benefits include faster execution of code when moving to .NET Core along with having the ability to use new features in C#8 and C#9.

The most challenging part of going to .NET Core is finding certain references such as in .NET Framework, in a class project if a reference for System.Windows.Forms was needed it's easy to do while in .NET Core one needs to find the reference by browsing to

C:\Program Files\dotnet\packs\Microsoft.WindowsDesktop.App.Ref\5.0.0\ref\net5.0

Then selecting System.Windows.Forms.dll

Or add commonly used references to the Object browser which also allows you to add a reference to the current project with a single click.

82773-f1.png

Cleaner code can be written e.g.

 public static void ConventionalExample()
 {
     using (var cn = new SqlConnection(ConnectionString))
     {
         cn.Open();
     }
 }
    
 public static void CoreExample()
 {
     using var cn = new SqlConnection(ConnectionString);
     cn.Open();
 }

In closing, best to use the older code as a bridge which gives time to write the .NET Core class project.



f1.png (21.0 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.