Reputation: 13
Currently I'm unable to add an assembly reference to my C# project in Visual Studio 2019.
I don't know if this is an error with Visual Studio itself or it's my fault.
Currently my References page looks like this:
If I try to add a COM Reference then I get the following error of:
Severity Code Description Project File Line Suppression State
Warning MSB3290 Failed to create the wrapper assembly for type library "{215d64d2-031c-33c7-96e3-
61794cd1ee61}". Type library 'System_Windows_Forms' was exported from a CLR assembly and cannot be
re-imported as a CLR assembly. MyProgram C:\Program Files (x86)\Microsoft Visual
Studio\2019\Community\MSBuild\Current\Bin\Microsoft.Common.CurrentVersion.targets 2705
All I want is to add a reference to Windows Forms.
Upvotes: 1
Views: 3091
Reputation: 109005
Reference to a type library would indcate you are adding a COM reference.
But System.Windows.Forms
is a .NET assembly, so you should be selecting it from the Assemblies list on the references manager (shown when you add reference).
If this is a .NET Core project then add the appropriate reference via NuGet (in project's context menu in solution explorer). But it also needs the right SDK version.
Probably easier to copy from a fresh WinForms project created from the VS New Project and see what NuGet references it included.
Correction
For .NET Core 3.1 you don't need any references for the WinForms assemblies. Instead you need the right settings in your .csproj
:
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Upvotes: 3
Reputation: 304
There could possibly because of you are trying to refer a COM library build on different architecture than the project you want to get the COM reference. For example COM lib may be built on x64 and your project may be built upon x32.
Or will you please elaborate your issue or help me on how to reproduce it.
Upvotes: 0