dotnet / winforms

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

Need an alternative solution for the ImageList.ImageStream in the .NET 9 designer. #12310

Open ElavazhaganSF4422 opened 1 month ago

ElavazhaganSF4422 commented 1 month ago

Environment

VS professional 2022 preview 17.12.0 preview 2.1

.NET version

.NET 9.0

Did this work in a previous version of Visual Studio and/or previous .NET release?

Yes, in the .NET 8.0 version, we are able to see the images in the designer. The ImageList.ImageStream is not supported starting from .NET 9 due to binary formatter serialization. Therefore, we have tried to avoid using ImageStream and added the images directly to the ImageList. In this case, the images load properly at runtime, but we are unable to see the images in the designer of projects targeted for .NET 9.

Issue description

Due to BinaryFormatter not supported in .NET 9 the ImageList.ImageStream will not support in .NET 9. . Therefore, we have tried to avoid using ImageStream and added the images directly to the ImageList. In this case, the images load properly at runtime, but we are unable to see the images in the designer of projects targeted for .NET 9.

Refer the screenshot from below,

ImageList with ImageStream screenshots in .NET 9 designer

Image

.ImageList with directly added images in .NET 9 designer

Image

We expected the image should be shown in the designer, but it is not shown properly. Is there any alternative solution we have to achieve this in both runtime and DesignTime

Steps to reproduce

1.Open the sample. 2.And then try to open the designer.

ImageList.zip

Observed Behavior : The Image List images are not shown in the designer. Image

Expected Behavior : The Image List images should be shown in the designer. Image

Diagnostics

No response

SathiyathanamSathish commented 1 month ago

@Everyone - Could you please share the work around to overcome this?

Zheng-Li01 commented 1 month ago

@SathiyathanamSathish, thanks for your update. reference this known issue https://github.com/dotnet/winforms/issues/9701, if your Visual Studio version newer than 17.12 preview2, and when your project upgrade to .NET 9 any form/control using an ImageList will not cause anything to break.

See comments that actually the System.Runtime.Serialization.Formatters nuget package will be installed by default if you Visual Studio version more than 17.12 preview2.

JeremyKuhne commented 1 month ago

@ElavazhaganSF4422 binary formatted designer resources (designer.resx) will work without needing to take the BinaryFormatter package dependency.

The .NET runtime can extract most embedded binary formatted resources without needing the BinaryFormatter package. Embedded resources are considered "trusted" data as they are part of the assembly, so we've put some effort into making this work, specifically with the WinForms design scenario in mind.

ElavazhaganSF4422 commented 1 month ago

@Zheng-Li01 The BinaryFormatter exception was thrown while using ImageList.ImageStream in .NET 9 samples with SDK version 9.5. However, after upgrading to .NET 9.0 SDK version RC1, the exception is no longer thrown. Why is this the case? Has ImageList.ImageStream been updated to use a different serialization method?"

JeremyKuhne commented 2 weeks ago

@ElavazhaganSF4422 as I mentioned above https://github.com/dotnet/winforms/issues/12310#issuecomment-2411927534 this scenario was enabled in the most recent previews of .NET 9. ImageList.ImageStream still uses the BinaryFormatter to serialize as an embedded designer resource.

dotnet-policy-service[bot] commented 2 days ago

This submission has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 14 days.

It will be closed if no further activity occurs within 7 days of this comment.