VSC C#: Referencing Microsoft DLLs

0

I'm trying to port a C# .NET Core project from Visual Studio 2019 to Visual Studio Code, although I have no experience with using VSC for C#. I managed to set up NuGet references using dotnet add package, however I cannot wrap my head around importing DLLs that are already present in Windows, such as System.Windows.Forms.

This has been done via a GUI menu in VS19, however that cannot be the case with Powershell commands. Futhermore, I used a Microsoft.Windows.Compatibility package to get it working on .NET Core, rather than .NET Framework. I attempted using dotnet add package System.Windows.Forms along dotnet add package Microsoft.Windows.Compatibility, however, after dotnet run, I get the following errors in the Terminal:

warning NU1701: Package 'System.Windows.Forms 4.0.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.

Unhandled exception. System.BadImageFormatException: Could not load file or assembly 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'. Reference assemblies should not be loaded for execution. They can only be loaded in the Reflection-only loader context. (0x80131058) File name: 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' ---> System.BadImageFormatException: Cannot load a reference assembly for execution.

How can I get this working in Visual Studio Code?

c#
.net
visual-studio
visual-studio-code
asked on Stack Overflow Jun 22, 2020 by RoundedToZero

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0