winforms icon indicating copy to clipboard operation
winforms copied to clipboard

DataSet corrupting Form Designer Code in NET 6

Open AberHatschi opened this issue 3 years ago • 5 comments

Description

So if you create a class something like

Public Class Test1 Inherits Control End Class

and compile so you are able to drag this class onto your form. The designer will create these lines: Friend WithEvents Testcontrol1 As testcontrol Me.Testcontrol1 = New ProjectName.testcontrol()

In this case the designer recognizes ProjectName as a Namespace

However if you add now a DataSet, the designer will treat ProjectName as a new class, and not like a namespace anymore. So you get error at the constructor of Testcontrol. If you add the DataSet first and then the control, the designer will even show you another way, it will produce now this code Friend WithEvents Testcontrol1 As ProjectName.testcontrol Me.Testcontrol1 = New ProjectName.testcontrol() Both lines throwing an error now

This project creates the issue consistently, but you can do it yourself too TestReduziert.zip .

Reproduction Steps

New Windows Form App Create your own control class to drag on form compile drag on form add a dataset

Expected behavior

you should be able to compile and start your application

Actual behavior

Program wont compile, because of error in designer code. (class not defined)

Regression?

It works in 4.6

Known Workarounds

You can manually edit the designer code and fix the errors, by deleting the namespace in front of your own class.

Configuration

NET 6 Windows 10

Other information

When adding the DataSet there is a new Namespace created ProjectName.ProjectName this is causing all of the above problems and makes it also obvious why you can fix it.

AberHatschi avatar Jul 12 '22 07:07 AberHatschi

Tagging subscribers to this area: @dotnet/area-meta See info in area-owners.md if you want to be subscribed.

Issue Details

Description

So if you create a class something like

Public Class Test1 Inherits Control End Class

and compile so you are able to drag this class onto your form. The designer will create these lines: Friend WithEvents Testcontrol1 As testcontrol Me.Testcontrol1 = New ProjectName.testcontrol()

In this case the designer recognizes ProjectName as a Namespace

However if you add now a DataSet, the designer will treat ProjectName as a new class, and not like a namespace anymore. So you get error at the constructor of Testcontrol. If you add the DataSet first and then the control, the designer will even show you another way, it will produce now this code Friend WithEvents Testcontrol1 As ProjectName.testcontrol Me.Testcontrol1 = New ProjectName.testcontrol() Both lines throwing an error now

This project creates the issue consistently, but you can do it yourself too TestReduziert.zip .

Reproduction Steps

New Windows Form App Create your own control class to drag on form compile drag on form add a dataset

Expected behavior

you should be able to compile and start your application

Actual behavior

Program wont compile, because of error in designer code. (class not defined)

Regression?

It works in 4.6

Known Workarounds

You can manually edit the designer code and fix the errors, by deleting the namespace in front of your own class.

Configuration

NET 6 Windows 10

Other information

No response

Author: AberHatschi
Assignees: -
Labels:

area-Meta

Milestone: -

ghost avatar Jul 12 '22 07:07 ghost

@DustinCampbell Can you help route this please? The linked zip file repro works for me and here's what I'm seeing after I add a new empty DataSet to the project:

  1. The Form1 code does not specify a namespace anywhere
  2. The CircularProgressBar code does not specify a namespace anywhere
  3. When adding a DataSet, the DataSet's generated code specifies a namespace that matches the project name
  4. This leads to ambiguity between an implicit namespace in Form1 and CircularProgressBar and the DataSet's explicitly specified namespace (where this results in a ProjectName.ProjectName namespace)

Is this an issue with the DataSet custom tool needing to recognize that the namespace should be implicit?

jeffhandley avatar Aug 02 '22 04:08 jeffhandley

Also tagging @davidwengier as there looks to be a little similarity to https://github.com/dotnet/project-system/issues/5589 which was addressed a couple years ago.

jeffhandley avatar Aug 02 '22 04:08 jeffhandley

@KlausLoeffelmann getting this on your radar.

merriemcgaw avatar Aug 18 '22 00:08 merriemcgaw

@AberHatschi: What are your exact steps to create a DataSet and add it to the Form for .NET Apps in this scenario?

Please note, that the Data Source Provider Services, which is responsible for Typed DataSet generation, is not enabled for .NET Apps, and therefore we have limited Designer support for (Typed) DataSets. Porting a Form directly from .NET Framework to .NET should work though, and also the Designer should parse the Form OK. On top, you should be able to do basic DataSet based binding operations like changing the bindings for certain Controls on the Form (or UserControl).

(For more info about DataBinding, please take a look here: https://devblogs.microsoft.com/dotnet/databinding-with-the-oop-windows-forms-designer/)

KlausLoeffelmann avatar Aug 18 '22 00:08 KlausLoeffelmann