Resolved Can not reference System.WindowsForms in Net5

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
110
Programming Experience
10+
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
I'm using System.Windows.Forms.StatusBarPanel. Could that be a problem in Net5?
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.

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
I'm using System.Windows.Forms.StatusBarPanel. Could that be a problem in Net5?
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.
 
Solution

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
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.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
The Import Includes in project file is for importing namespaces (at project level) for existing referenced assemblies by the way.
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
It should just be "Import System.Windows.Forms" less the quotation marks and remebering the "." period(s).
 

jmcilhinney

VB.NET Forum Moderator
Staff member
Joined
Aug 17, 2004
Messages
14,496
Location
Sydney, Australia
Programming Experience
10+
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.
 

ProtekNickz

Well-known member
Joined
Oct 22, 2009
Messages
130
Location
UK
Programming Experience
1-3
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:

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 :p.



ProtekNickz xD
 

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
110
Programming Experience
10+
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.
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>
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
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.
 

aaaron123@roadrunner.com

Well-known member
Joined
Jan 23, 2011
Messages
110
Programming Experience
10+
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.
 

JohnH

VB.NET Forum Moderator
Staff member
Joined
Dec 17, 2005
Messages
15,545
Location
Norway
Programming Experience
10+
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
 
Top Bottom