Bitmap Property Serialization Error in Custom Control
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
- Open the Designer.
- Select the CustomButton and go to the Properties window.
- 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 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.
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).
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.