winforms icon indicating copy to clipboard operation
winforms copied to clipboard

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

Open ElavazhaganSF4422 opened this issue 1 year ago • 4 comments

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

ElavazhaganSF4422 avatar Oct 11 '24 12:10 ElavazhaganSF4422

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

SathiyathanamSathish avatar Oct 14 '24 05:10 SathiyathanamSathish

@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.

Zheng-Li01 avatar Oct 14 '24 07:10 Zheng-Li01

@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.

JeremyKuhne avatar Oct 14 '24 18:10 JeremyKuhne

@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?"

ElavazhaganSF4422 avatar Oct 23 '24 08:10 ElavazhaganSF4422

@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.

JeremyKuhne avatar Nov 06 '24 21:11 JeremyKuhne

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.