dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.41k stars 982 forks source link

[dotnet-sdk-9.0.100-rc.2.24470.13] Some Winfroms Apps build with error: Property 'XXX' does not configure the code serialization for its property content #12220

Closed Junjun-zhao closed 1 month ago

Junjun-zhao commented 1 month ago

.NET version

Dotnet Info:

.NET SDK:
 Version:           9.0.100-rc.2.24470.13
 Commit:            3229e54b07
 Workload version:  9.0.100-manifests.8fbc914b
 MSBuild version:   17.12.0-preview-24469-05+fea15fbd1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win-x64
 Base Path:   C:\Program Files\dotnet\sdk\9.0.100-rc.2.24470.13\

Host:
  Version:      9.0.0-rc.2.24463.7
  Architecture: x64
  Commit:       static

.NET SDKs installed:
  9.0.100-rc.2.24470.13 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 9.0.0-rc.2.24466.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 9.0.0-rc.2.24463.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 9.0.0-rc.2.24464.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Did it work in .NET Framework?

Not tested/verified

Did it work in any of the earlier releases of .NET Core or .NET 5+?

Yes

Verify Scenarios: 1). Windows 10 21H2 AMD64 + dotnet-sdk-8.0.300(default target net8.0): Pass 2). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.2.24470.13(default target net8.0): Pass 3). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.2.24470.13(retarget net9.0): Fail 4). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-rc.1.24452.12(retarget net9.0): Fail 5). Windows 10 21H2 AMD64 + dotnet-sdk-9.0.100-preview.7.24407.12(retarget net9.0): Pass

Issue description

When retarget the 3rd party application to net9.0 and build with the latest .NET 9 sdk, it failed with error: Property 'CellTemplate' does not configure the code serialization for its property content.

Application Name: WinformsSamples, mRemoteNG, Character-Builder-5, AutoVersionsDB,HeroesPowerPlant OS: Windows 10 21H2 CPU: X64 .NET Build Number: dotnet-sdk-9.0.100-rc.2.24470.13 App & Source checking at: https://devdiv.visualstudio.com/DevDiv/_workitems/edit/2260303 Github Link: GitHub - dotnet/samples: Sample code referenced by the .NET documentation

Steps to reproduce

App Repro Steps:(dotnet-sdk-9.0.100-rc.2.24470.13 installed) 1.Retarget app to net9.0 in \WinformsAPP\datagridview\CSWinFormDataGridView\CSWinFormDataGridView.csproj

net9.0-windows
  1. Run command "dotnet build" in \WinformsAPP\datagridview\CSWinFormDataGridView.

Expected Result: Build successfully.

Actual Result: Build failed with error: WFO1000: Property 'CellTemplate' does not configure the code serialization for its property content.

Minimal Repro Steps (Demo attached:WinformsDemo.zip):

  1. Create a default8.0 winforms project.
  2. Create Class1.cs.
    internal class Class1 : DataGridViewColumn
    {
    private string test;
    public string Test
    {
        get
        {
            return this.test;
        }
        set
        {  
        }
    }
    }
  3. Retarget to net9.0.
  4. Build with dotnet-sdk-9.0.100-rc.2.24470.13.

Expected Result: Build successfully.

Actual Result: Build failed with error: Property 'Test' does not configure the code serialization for its property content.

Findings: There is a similar issue filed on github: DesignerSerializationVisibility - Behaviour Changes · Issue #41964 · dotnet/docs (github.com) This issue starts from .NET 9 RC1 release and if we use the workaround mentioned in above issue to add DesignerSerializationVisibility to property, error will go. [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

@dotnet-actwx-bot @dotnet/compat

Junjun-zhao commented 1 month ago

@merriemcgaw Could you please take a look at this issue? There are 5 apps affected in our lab.

CC: @richaverma1 @PriyaPurkayastha @marklio for awareness.

PriyaPurkayastha commented 1 month ago

Adding @KlausLoeffelmann per chat with @merriemcgaw. Also cc @gewarren since customer created an issue for missing doc linked above. @KlausLoeffelmann is this an intentional breaking change (the analyzer work done as part of binary formatter removal) that hasn't been documented? Can you please create a breaking change issue for this using the template https://github.com/dotnet/docs/issues/new?assignees=gewarren&labels=breaking-change%2CPri1%2Cdoc-idea&projects=&template=02-breaking-change.yml&title=%5BBreaking+change%5D%3A+

PriyaPurkayastha commented 1 month ago

Also adding @JeremyKuhne as requested by @merriemcgaw

KlausLoeffelmann commented 1 month ago

This is by design, introduced with .NET 9 (RC1). We need to make sure for security reasons, that properties for WinForms Designer are not serialized by accident.

We will follow up with a respective Blog Post shortly.

In the meanwhile, please fix the CodeDOM Serialization configuration for properties according to WinForms best practices:

PriyaPurkayastha commented 1 month ago

@KlausLoeffelmann thanks for confirming. However, our breaking change process for .NET is that whenever we introduce a breaking change, it has to be accompanied by a breaking change doc in the very same release so that customers that start using the new release are not taken by surprise (like we saw with this change where two customers as well as .NET AppCompat lab did not know to expect this). Request you to kindly create the breaking change doc issue using the template provided above immediately. The blog post will definitely help everyone but does not substitute the breaking change documentation.

KlausLoeffelmann commented 1 month ago

OK, yes, that makes sense!

I created this and will make sure the blog post will be out ASAP! (It's almost done, so, no problem).

https://github.com/dotnet/docs/issues/42724

@JeremyKuhne, @merriemcgaw.

kirsan31 commented 1 month ago

@KlausLoeffelmann I think it would be helpful to point out default behaviour:

Members that do not have a DesignerSerializationVisibilityAttribute will be treated as though they have a DesignerSerializationVisibilityAttribute with a value of Visible. The values of a property marked as Visible will be serialized, if possible, by a serializer for the type.

Junjun-zhao commented 1 month ago

@KlausLoeffelmann Thank you for creating the breaking change doc quickly. Could you please close this issue? Thanks.