Resolved - Can not reference System.WindowsForms in Net5 (2024)

  • VB.NET
  • Windows Forms
  • Thread starteraaaron
  • Start dateJan 17, 2021

A

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
  • Jan 17, 2021
  • #1

I'm converting to Net5. I have 40 out of 41 projects converted OK

The remaining project will not let me reference System.WindowsForms.

There are two versions of System.WindowsForms, I've been using 2.4 routinely (I hope that's what I should be doing).

I tried them both in the troublesome procedure.

What happens is: I select Project/Add COM Reference and then check System.WindowsForms.

Close the dialog and reopen it and see that the check is gone.

I did this because checking it did not have any effect on the error I was trying to fix.

I'm using System.Windows.Forms.StatusBarPanel. Could that be a problem in Net5?

BTW. I also tried including:

VB.NET:

 <ItemGroup> <Import Include="Microsoft.VisualBasic" /> <Import Include="System" /> <Import Include="System.Collections" /> <Import Include="System.Collections.Generic" /> <Import Include="System.Data" /> <Import Include="System.Drawing" /> <Import Include="System.Diagnostics" /> <Import Include="System.Windows.Forms" /> <Import Include="System.Linq" /> <Import Include="System.Xml.Linq" /> <Import Include="System.Threading.Tasks" /> </ItemGroup>

In that case I also checked System.WindowsForms (I'm not sure it would show checked) but it was not checked.

Last edited:

Solution

  • JohnH

  • Jan 17, 2021

aaaron123@roadrunner.com said:

I'm using System.Windows.Forms.StatusBarPanel. Could that be a problem in Net5?

Resolved - Can not reference System.WindowsForms in Net5 (3)

StatusBarPanel Class (System.Windows.Forms)

Represents a panel in a StatusBar control. This class is not available in .NET 5 and later versions. Use the ToolStripStatusLabel control instead, which replaces and extends the StatusBarPanel control.

docs.microsoft.com

This class is not available in .NET 5.0 and later versions. Use the StatusStrip control instead, which replaces and extends the StatusBar control.

MenuStrip/ToolStrip/StatusStrip were introduced as replacements for Menu/ToolBar/StatusBar in .Net 2.0.

Sort by dateSort by votes

JohnH

VB.NET Forum Moderator

Staff member

Joined
Dec 17, 2005
Messages
15,809
Location
Norway
Programming Experience
10+
  • Jan 17, 2021
  • #2

aaaron123@roadrunner.com said:

I'm using System.Windows.Forms.StatusBarPanel. Could that be a problem in Net5?

Resolved - Can not reference System.WindowsForms in Net5 (5)

StatusBarPanel Class (System.Windows.Forms)

Represents a panel in a StatusBar control. This class is not available in .NET 5 and later versions. Use the ToolStripStatusLabel control instead, which replaces and extends the StatusBarPanel control.

docs.microsoft.com

This class is not available in .NET 5.0 and later versions. Use the StatusStrip control instead, which replaces and extends the StatusBar control.

MenuStrip/ToolStrip/StatusStrip were introduced as replacements for Menu/ToolBar/StatusBar in .Net 2.0.

Upvote0Downvote

Solution

JohnH

VB.NET Forum Moderator

Staff member

Joined
Dec 17, 2005
Messages
15,809
Location
Norway
Programming Experience
10+
  • Jan 17, 2021
  • #3

aaaron123@roadrunner.com said:

The remaining project will not let me reference System.WindowsForms.

There are two versions of System.WindowsForms, I've been using 2.4 routinely (I hope that's what I should be doing).

I tried them both in the troublesome procedure.

What happens is: I select Project/Add COM Reference and then check System.WindowsForms.

No, you shouldn't. When <UseWindowsForms> is added to SDK project file the Microsoft.WindowsDesktop.App.WindowsForms framework dependency is added, this includes .Net 5 version of System.Windows.Forms.dll. Expand Dependencies in Solution Explorer and you'll see it.

Upvote0Downvote

JohnH

VB.NET Forum Moderator

Staff member

Joined
Dec 17, 2005
Messages
15,809
Location
Norway
Programming Experience
10+
  • Jan 17, 2021
  • #4

The Import Includes in project file is for importing namespaces (at project level) for existing referenced assemblies by the way.

Upvote0Downvote

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
  • Jan 18, 2021
  • #5

It should just be "Import System.Windows.Forms" less the quotation marks and remebering the "." period(s).

Upvote0Downvote

jmcilhinney

VB.NET Forum Moderator

Staff member

Joined
Aug 17, 2004
Messages
15,078
Location
Sydney, Australia
Programming Experience
10+
  • Jan 18, 2021
  • #6

ProtekNickz said:

It should just be "Import System.Windows.Forms" less the quotation marks and remebering the "." period(s).

Nope. That's just importing a namespace at the file level. It's only tangentially related to referencing an assembly.

Upvote0Downvote

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
  • Jan 18, 2021
  • #7

jmcilhinney said:

Nope. That's just importing a namespace at the file level. It's only tangentially related to referencing an assembly.

Ah well he/she did state in their first post that:

aaaron123@roadrunner.com said:

There are two versions of System.WindowsForms, I've been using 2.4 routinely (I hope that's what I should be doing).

and I just seen they missed a period, so ty for correcting me Resolved - Can not reference System.WindowsForms in Net5 (11).

ProtekNickz xD

Upvote0Downvote

A

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
  • Jan 18, 2021
  • #8

Microsoft.Common.CurrentVersion.targets(2701,5): 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.

JohnH said:

No, you shouldn't. When <UseWindowsForms> is added to SDK project file the Microsoft.WindowsDesktop.App.WindowsForms framework dependency is added, this includes .Net 5 version of System.Windows.Forms.dll. Expand Dependencies in Solution Explorer and you'll see it.

Thanks for the above. I'm getting use to looking at the Dependencies!

If I understand what you told me I have duplicates WindowsForms entries in the code below.

I think this {215d64d2-031c-33c7-96e3-61794cd1ee61} related to windowsforms (where is there a list of such Guids?)

And I think it is there because I added the reference to remove an error message.

If I now remove it I get many WindowsForms error messages again.

Like: MessageBox is not declared.

I'd appreciate any suggestions related to fixing the below.

BTW. It works as is but I want to take you reply seriously.

I'm still working on the other's replies!

VB.NET:

<Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <RootNamespace>Cag.TextEditor</RootNamespace> <TargetFramework>net5.0-windows</TargetFramework> <UseWindowsForms>true</UseWindowsForms> <MyType>WindowsForms</MyType> </PropertyGroup> <ItemGroup> <COMReference Include="{215d64d2-031c-33c7-96e3-61794cd1ee61}"> <WrapperTool>tlbimp</WrapperTool> <VersionMinor>4</VersionMinor> <VersionMajor>2</VersionMajor> <Guid>215d64d2-031c-33c7-96e3-61794cd1ee61</Guid> </COMReference> <COMReference Include="tom.dll"> <WrapperTool>tlbimp</WrapperTool> <VersionMinor>0</VersionMinor> <VersionMajor>1</VersionMajor> <Guid>8cc497c9-a1df-11ce-8098-00aa0047be5d</Guid> <Lcid>0</Lcid> <Isolated>false</Isolated> </COMReference> <COMReference Include="{bee4bfec-6683-3e67-9167-3c0cbc68f40a}"> <WrapperTool>tlbimp</WrapperTool> <VersionMinor>4</VersionMinor> <VersionMajor>2</VersionMajor> <Guid>bee4bfec-6683-3e67-9167-3c0cbc68f40a</Guid> </COMReference> </ItemGroup> <ItemGroup> <ProjectReference Include="..\BitmapEditor\BitmapEditor.vbproj" /> <ProjectReference Include="..\ColorUtilities\ColorUtilities.vbproj" /> <ProjectReference Include="..\FractionUpDown\FractionUpDown.vbproj" /> <ProjectReference Include="..\LibraryCs2\LibraryCs2.csproj" /> <ProjectReference Include="..\LibraryDisk1\LibraryDisk1.vbproj" /> <ProjectReference Include="..\LibraryGraphic2\LibraryGraphic2.vbproj" /> <ProjectReference Include="..\LibraryNative0\LibraryNative0.vbproj" /> <ProjectReference Include="..\LibraryPrinter1\LibraryPrinter1.vbproj" /> <ProjectReference Include="..\LibraryTextEditor2\LibraryTextEditor2.vbproj" /> <ProjectReference Include="..\LibraryVb0\LibraryVb0.vbproj" /> <ProjectReference Include="..\LibraryVb1\LibraryVb1.vbproj" /> <ProjectReference Include="..\LibraryVb3\LibraryVb3.vbproj" /> <ProjectReference Include="..\UpDowns\UpDowns.vbproj" /> </ItemGroup></Project>

Upvote0Downvote

JohnH

VB.NET Forum Moderator

Staff member

Joined
Dec 17, 2005
Messages
15,809
Location
Norway
Programming Experience
10+
  • Jan 18, 2021
  • #9

You're missing the namespace imports at project level. (the Import Include)

In case you didn't know, you add references to assemblies (dll libraries) which in this case is part of single huge dependency package so that they can be loaded when your app loads, and import namespaces in order to use classes within those libraries. One dll can have many classes/types organized into namespaces. Some namespaces are imported at project project level because they are used all over the place, for example the System.Windows.Forms namespace, others that you use more occationally in a single code file you import with the Imports statement at top of the code file.

Upvote0Downvote

A

aaaron

Well-known member
Joined
Jan 23, 2011
Messages
219
Programming Experience
10+
  • Jan 18, 2021
  • #10

JohnH said:

You're missing the namespace imports at project level. (the Import Include)

1)Are you refering to
<OutputType>WinExe</OutputType>

What I should have included but didn't is the fact that in the file that works under Dependencies / Frameworks there is
MicrosoftWindowsDesktop.App.WindoesForms and, in the project file I have 215d64d2-031c-33c7-96e3-61794cd1ee61

I think I shouldn't need nor want two references to WindowsForms.

2)If I now remove {215d64d2-031c-33c7-96e3-61794cd1ee61} I get many WindowsForms error messages again.

Like: MessageBox is not declared.

I may have misinterpreted your earlier message but I thought MicrosoftWindowsDesktop.App.WindoesForms was what I needed.

Upvote0Downvote

JohnH

VB.NET Forum Moderator

Staff member

Joined
Dec 17, 2005
Messages
15,809
Location
Norway
Programming Experience
10+
  • Jan 18, 2021
  • #11

No I said

Import Include

. As explained to be able to use a library it must be referenced that is that <UseWindowsForms> does, it add a bunch of libraries. Then you must import the namespaces, if not every type used in code must be qualified with the namespace, for example you can't write MessageBox, it must be System.Windows.Forms.MessageBox. Obviously a form with lots of Forms types in generated code will not compile.
This is also explained in point 3 of VB extras in the migration guide that I posted before: Migrate a Windows Forms app to .NET 5 - Windows Forms .NET

Upvote0Downvote

Similar threads

F

  • Locked
  • Question

QuestionAdd reference for winSCP DLL not working in Production Server

  • FirasKassim
  • Apr 29, 2015
  • Third Party/Add-Ins
Replies
1
Views
10K

Apr 29, 2015

JohnH

J

  • Question

Reference in the manifest does not match the identity of the downloaded assembly

  • JA12
  • May 16, 2014
  • Deployment
Replies
6
Views
15K

Feb 18, 2015

JeremyLeach

J

G

  • Question

Not set to instance of object for Service Reference

  • GrexD
  • May 22, 2012
  • VB.NET General Discussion
Replies
2
Views
2K

May 23, 2012

GrexD

G

  • Question

Problem with MDAC registration/registry problem, cannot add reference to ADO 6.0.

  • Herman
  • Feb 22, 2012
  • VS.NET General Discussion
Replies
0
Views
2K

Feb 22, 2012

Herman

E

  • Question

custom VBproj MSBuild project

  • Evan1993
  • Nov 3, 2009
  • VB.NET General Discussion
Replies
0
Views
3K

Nov 3, 2009

Evan1993

E

Share this page

Latest posts

  • ResolvedGraphics in paint only?

    • Latest: jmcilhinney

    Graphics/GDI+

  • How can I validate Date.Now?

    • Latest: genesix

    VB.NET General Discussion

  • Salesforce CPQ - Product Rules Firing Timing

    • Latest: vivansai1

    Training, Conferences, Events

  • Questionwhat conftest.py should look like?

    • Latest: jmcilhinney

    Web Services

  • A

    Questionhow to calculate in vb.net the nth root for biginteger

    • Latest: andrews

    VB.NET General Discussion

  • VB.NET
  • Windows Forms
Resolved - Can not reference System.WindowsForms in Net5 (2024)

FAQs

How to add system windows forms in .net core? ›

Create a . NET Core project
  1. Step 1: Open Visual Studio, go to File > New > Project… and you can now see Create a new project dialog. ...
  2. Step 2: You will now see Configure your new project dialog. ...
  3. Step 3: In the Additional information window, select . ...
  4. Step 4: Finally, Windows Forms (. ...
  5. Step 5: Now, you can add your controls.

How do I add system windows forms to Visual Studio? ›

In Visual Studio, find the Project Explorer pane. Right-click on the project and choose Add > Form (Windows Forms). In the Name box, type a name for your form, such as MyNewForm. Visual Studio will provide a default and unique name that you may use.

How to add system windows forms reference in WPF? ›

Hosting the Windows Forms Control
  1. Create a WPF Application project named HostingWfInWpfWithXaml .
  2. Add references to the following assemblies. ...
  3. Open MainWindow. ...
  4. In the Window element, add the following namespace mapping. ...
  5. In the Grid element add the following XAML. ...
  6. Press F5 to build and run the application.
Feb 6, 2023

How do I add a system reference in .NET core? ›

One method of adding references to your library is by typing it directly in the project. json file. As you can see that we have added some references under the dependencies section as shown in the following code. Let us now save this file and you will see that references are added to your library now.

Is WinForms supported in .NET 6? ›

NET 6 introduced many changes to the standard console application templates. In line with those changes, the Windows Forms templates for C# have been updated to enable global using directives, file-scoped namespaces, and nullable reference types by default.

How do I add references to Windows forms in Visual Studio? ›

Add a reference
  1. In Solution Explorer, right-click the References or Dependencies node, and then choose either Add Project Reference, Add Shared Project Reference, or Add COM Reference from the context menu. ...
  2. Select a reference to add, and then select OK.
Oct 31, 2023

How do I install Windows forms in Visual Studio? ›

Install through the Visual Studio Manage Extensions
  1. Open the Visual Studio.
  2. Navigate to Extension ->Manage Extensions and open the Manage Extensions. ...
  3. On the left, click the Online tab and type “Syncfusion Windows” in the search box.
  4. Click the Download button in the “WinForms Extensions - Syncfusion”.

How to add an existing Windows form in C#? ›

Select Visual Studio menu Project -> Add Existing Item... Then select (browse) in the file dialog the Form. cs (Form = name of the form) you want to add to the project and the form (with all associated files) is (copied and) added to your project.

How do I add a Windows Form to Visual Studio code? ›

Visual Studio opens your new project.
  1. Open Visual Studio.
  2. On the start window, select Create a new project.
  3. In Create a new project, select the Windows Forms App (. NET Framework) template for C#. ...
  4. In the Configure your new project window, in Project name, enter HelloWorld, and select Create.
Mar 28, 2024

Where is System Windows Forms Design DLL? ›

System. Windows. Forms. dll is located in the folder C:\WINDOWS\Microsoft.NET\Framework\v2.

How to install Windows form in C#? ›

Create a project
  1. Open Visual Studio.
  2. On the start window, choose Create a new project.
  3. In Create a new project, choose the Windows Forms App (. NET Framework) template for C#. ...
  4. In Configure your new project, for Project name, enter HelloWorld and select Create. Visual Studio opens your new project.
Mar 28, 2024

What is system Windows Forms in C#? ›

Windows Forms is a Graphical User Interface(GUI) class library which is bundled in . Net Framework. Its main purpose is to provide an easier interface to develop the applications for desktop, tablet, PCs. It is also termed as the WinForms.

How do I add Windows authentication to Netcore? ›

New project
  1. Create a new project.
  2. Select ASP.NET Core Web Application. Select Next.
  3. Provide a name in the Project name field. ...
  4. Select Change under Authentication.
  5. In the Change Authentication window, select Windows Authentication. ...
  6. Select Web Application.
  7. Select Create.
Apr 25, 2023

Top Articles
Latest Posts
Article information

Author: Rubie Ullrich

Last Updated:

Views: 6161

Rating: 4.1 / 5 (52 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Rubie Ullrich

Birthday: 1998-02-02

Address: 743 Stoltenberg Center, Genovevaville, NJ 59925-3119

Phone: +2202978377583

Job: Administration Engineer

Hobby: Surfing, Sailing, Listening to music, Web surfing, Kitesurfing, Geocaching, Backpacking

Introduction: My name is Rubie Ullrich, I am a enthusiastic, perfect, tender, vivacious, talented, famous, delightful person who loves writing and wants to share my knowledge and understanding with you.