Skip to content

Commit 4e76345

Browse files
committed
winforms: fix title and lint issues
1 parent f793dcc commit 4e76345

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

docs/standard/serialization/binaryformatter-migration-guide/winforms-migration-guide.md

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ helpviewer_keywords:
77
- "BinaryFormatter"
88
- "WinForms"
99
---
10+
# WinForms Migration Guide
1011

1112
# BinaryFormatter Removal
1213

@@ -15,6 +16,7 @@ Starting in .NET 9, BinaryFormatter is being moved to a separate, unsupported nu
1516
# How BinaryFormatter Affects WinForms
1617

1718
WinForms itself has and still currently contains BinaryFormatter code internally for scenarios such as clipboard, drag/drop, and designer ResX, however, measures have been taken to mitigate the usage of BinaryFormatter behind the scenes for common primitive types, including primitive arrays and primitive lists. Usage of these types in clipboard and drag/drop scenarios will continue to work without using BinaryFormatter and without any gesture from the developer. Primitive types include the following
19+
1820
- `boolean`
1921
- `byte`
2022
- `char`
@@ -31,39 +33,44 @@ WinForms itself has and still currently contains BinaryFormatter code internally
3133
- `nuint`
3234

3335
Additional types WinForms currently supports include the following
36+
3437
- `PointF`
3538
- `RectangleF`
3639
- `Bitmap`
3740
- `ImageListStreamer`
3841

3942
## Clipboard
43+
4044
If your clipboard scenario does not involve the types above, BinaryFormatter would be used when [`Clipboard.SetData`](https://learn.microsoft.com/dotnet/api/system.windows.clipboard.setdata) is called with your type and when [`Clipboard.GetData`](https://learn.microsoft.com/dotnet/api/system.windows.clipboard.getdata) is called to get your type. BinaryFormatter will also be used if [`Clipboard.SetDataObject(object, copy: true)`](https://learn.microsoft.com/dotnet/api/system.windows.clipboard.setdataobject#system-windows-clipboard-setdataobject(system-object-system-boolean)) is called. With the BinaryFormatter removal, developers will now see a string about BinaryFormatter being removed on the clipboard when using those APIs with unsupported types.
4145

4246
## Drag/Drop
43-
If your drag/drop scenario involves unsupported types, BinaryFormatter would be used when [`Control.DoDragDrop`](https://learn.microsoft.com/dotnet/api/system.windows.forms.control.dodragdrop) is called, and the item is dragged out of process and when DataObject.GetData is called to retrieve your type that has been dragged out of process. With the BinaryFormatter removal, developers will now see a string about BinaryFormatter being removed upon dropping the dragged item in another process when a drag operation starts with unsupported types.
47+
48+
If your drag/drop scenario involves unsupported types, BinaryFormatter would be used when [`Control.DoDragDrop`](https://learn.microsoft.com/dotnet/api/system.windows.forms.control.dodragdrop) is called, and the item is dragged out of process and when DataObject.GetData is called to retrieve your type that has been dragged out of process. With the BinaryFormatter removal, developers will now see a string about BinaryFormatter being removed upon dropping the dragged item in another process when a drag operation starts with unsupported types.
4449

4550
## The WinForms Designer
46-
The WinForms designer also uses BinaryFormatter internally for ResX serialization/deserialization and CodeDom.
51+
52+
The WinForms designer also uses BinaryFormatter internally for ResX serialization/deserialization and CodeDom.
4753

4854
Types and properties may be participating in serialization without developers realizing due to the standard behavior of the WinForms designer. One way that BinaryFormatter is used where developers may not be aware of is when a property on a UserControl is introduced and that control is already populated at design-time, then it’s very likely that that data gets serialized into code or resource files. If all the following are true:
55+
4956
- A property contains data at the time when a Form in the Designer gets saved
5057
- that property is not attributed with `DesignerSerializationVisibility(false)`
5158
- that property does not have a DefaultValueAttribute
5259
- that property does not have a respective bool ShouldSerialize\[PropertyName\] method returning false
5360

54-
the Designer looks if that property’s type has a type converter. If it does then it uses it to serialize the property content, otherwise BinaryFormatter is used to serialize the content into the resource file.
61+
the Designer looks if that property’s type has a type converter. If it does then it uses it to serialize the property content, otherwise BinaryFormatter is used to serialize the content into the resource file.
5562
WinForms has added analyzers along with code fixes to help bring awareness to this type of behavior where BinaryFormatter serialization may be occurring without the developer’s knowledge.
5663

57-
58-
5964
# Migrating Away from BinaryFormatter
6065

6166
If unsupported types are used in the affected scenarios, action will need to be taken to complete migration to .NET 9+.
6267

6368
## Clipboard and Drag/Drop
69+
6470
For unsupported types that are used in clipboard and drag/drop operations, it is recommended developers format those types as a byte[] or string payload before passing the data to clipboard or drag/drop APIs. Using JSON is one way to achieve this. Note that adjustments will need to be made to handle receiving a JSON formatted type just as adjustments have been made to place JSON formatted types on clipboard or drag/drop operations. For more information on how to serialize/deserialize the type with JSON, see [How to write .NET objects as JSON (serialize)](https://learn.microsoft.com/dotnet/standard/serialization/system-text-json/how-to)
6571

6672
## Designer Scenarios
73+
6774
For unsupported types that are being serialized into resources/code, which would be the case for the designer with ResX and CodeDom serialization scenarios, the prescribed way of migrating away from BinaryFormatter is to ensure a TypeConverter is registered to the type or property that is participating in serialization. This way, during serialization/deserialization, the TypeConverter will be used in lieu of where BinaryFormatter was once used. For more information on implementing a type converter, see [TypeConverter Class](https://learn.microsoft.com/dotnet/api/system.componentmodel.typeconverter#notes-to-inheritors)
6875

6976
# Compatibility Workaround (Not Recommended)

0 commit comments

Comments
 (0)