DEV Community

Baki Gervalla
Baki Gervalla

Posted on

WinForms/WPF to .NET 10: the 6 breaking changes that actually bite

Support for .NET 8 and .NET 9 ended on 10 November. The next stop is .NET 10, the LTS release supported until November 2028.

Microsoft's breaking-changes list for .NET 10 is long, and most of it is about ASP.NET Core, the SDK and the runtime. If you maintain a WinForms or WPF app, six items matter. Here they are, with the fix for each.

The 6 breaking changes, with symptom and fix

1. New WinForms obsoletion warnings (WFDEV004, WFDEV005, WFDEV006)

Symptom: new build warnings. With TreatWarningsAsErrors, the build fails.

  • WFDEV004: Form.OnClosing, Form.OnClosed and the Closing/Closed events. Use OnFormClosing, OnFormClosed, FormClosing and FormClosed.
  • WFDEV005: Clipboard.GetData(string). Use Clipboard.TryGetData.
  • WFDEV006: ContextMenu, MainMenu, Menu, DataGrid, StatusBar, ToolBar. They exist only for binary compatibility with .NET Framework. Move to ContextMenuStrip, MenuStrip, DataGridView, StatusStrip and ToolStrip.

Fix: follow the link on each warning. If you can't fix one yet, suppress that ID only (<NoWarn>$(NoWarn);WFDEV006</NoWarn>), not all obsoletion warnings.

2. MenuItem and ContextMenu are now ambiguous in mixed WinForms + WPF projects

Symptom: CS0104 'ContextMenu' is an ambiguous reference between 'System.Windows.Controls.ContextMenu' and 'System.Windows.Forms.ContextMenu'.

From .NET Core 3.1 to .NET 9 these types existed only in WPF. .NET 10 adds them back to WinForms, so a project with both UseWindowsForms and UseWPF (and implicit usings) no longer compiles. Menu, DataGrid, ToolBar and StatusBar have the same problem.

Fix: add an alias for the one you mean:

using ContextMenu = System.Windows.Controls.ContextMenu;
Enter fullscreen mode Exit fullscreen mode

3. WPF: empty ColumnDefinitions and RowDefinitions don't compile

Symptom: error MC3063: Property 'ColumnDefinitions' does not have a value.

A leftover empty <Grid.ColumnDefinitions></Grid.ColumnDefinitions> used to compile. It doesn't any more, because of the new Grid shorthand syntax.

Fix: delete the empty element, or give it at least one <ColumnDefinition /> (or <RowDefinition />).

4. WPF: a wrong DynamicResource type now crashes the app

Symptom: XamlParseException: Set property 'System.Windows.ResourceDictionary.Source' threw an exception. at startup or when a window opens.

Before, using the wrong resource type with DynamicResource (for example a SolidColorBrush where a Color is expected) fell back to the default value and wrote an exception to the output window. Nobody noticed. Now it crashes.

Fix: use the right type:

<Color x:Key="RedColor">#FFFF0000</Color>
<SolidColorBrush x:Key="ResourceName" Color="{DynamicResource RedColor}" />
Enter fullscreen mode Exit fullscreen mode

This one doesn't show up at compile time, so open every window and theme once.

5. System.Drawing throws ExternalException, not OutOfMemoryException

Symptom: a corrupt or unsupported image used to throw OutOfMemoryException, which your code caught. Now GDI+ errors throw ExternalException, and your catch block misses it.

Fix: search for catch (OutOfMemoryException around Image.FromFile, Bitmap and other System.Drawing calls, and catch ExternalException too.

6. TreeView checkboxes are cut off in owner-draw mode

Symptom: with CheckBoxes = true, DrawMode = OwnerDrawText and DrawDefault = true, the checkbox images are cut off on the right.

Fix: it's opt-in. Add this to runtimeconfig.template.json:

{
  "configProperties": {
    "System.Windows.Forms.TreeView.MoveTreeViewTextLocationOnePixel": true
  }
}
Enter fullscreen mode Exit fullscreen mode

Coming from .NET 9, not .NET 8? StatusStrip goes back to RenderMode = System by default in .NET 10, so it can look slightly different. Set RenderMode explicitly if the look matters.

The order to do it in

  1. Change the target framework to net10.0-windows and update your control vendor packages (DevExpress, Telerik, Syncfusion) to versions that support .NET 10.
  2. Fix the compile errors: the CS0104 ambiguities and MC3063 grids.
  3. Fix or suppress the WFDEV warnings, one ID at a time.
  4. Fix the runtime changes: DynamicResource types and OutOfMemoryException catch blocks. Open every window once.
  5. Test on a clean machine with the .NET 10 Desktop Runtime and update the installer's runtime check.

On an app that already runs on .NET 8, this usually takes a few days, not weeks. Coming from .NET Framework 4.x is a bigger job; see my .NET 8 migration checklist for the extra steps.


Don't want to do this yourself? We migrate WinForms and WPF apps to .NET 10 at a fixed price: WinForms/WPF to .NET 10 migration on Upwork.

Top comments (0)