winforms icon indicating copy to clipboard operation
winforms copied to clipboard

Bitmap Property Serialization Error in Custom Control

Open Malini-SF4235 opened this issue 1 month ago • 2 comments

Environment

Visual Studio professional 2026 - version 18.0.0

.NET version

Facing this issue in .NetCore

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

No

Issue Description

I have a property of type Bitmap. When I add an image using this property, the following issue occurs: Property value is not valid (Could not serialize value 'System.Drawing.Bitmap' as 'System.Drawing.Bitmap').

Demo Link

CustomControl_Bitmap_Issue.zip

Issue replication video

https://github.com/user-attachments/assets/bd038418-f826-48cf-9fa6-f8d8f64e2c50

Steps to reproduce

  1. Open the Designer.
  2. Select the CustomButton and go to the Properties window.
  3. Click the Icon property and try to add an image.

Expected Behavior: The image should be added properly when adding it through the Icon property. Observed Behavior: The image was not added properly.

Malini-SF4235 avatar Nov 25 '25 06:11 Malini-SF4235

@Malini-SF4235 I've modified the demo you provided; it now allows image uploads. And the error was caused by forcing “content” serialization on a type (Bitmap) that only supports resource (binary) serialization in the WinForms designer. Removing DesignerSerializationVisibility.Content (or changing the property type to Image) resolves it.

CustomControl_Bitmap_Fix.zip

By the way, naming the property Icon while its type is Bitmap may trigger an Icon editor or confuse the designer’s type association (the designer expects Icon type when property is called Icon).

SimonZhao888 avatar Nov 27 '25 07:11 SimonZhao888

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.