Edit

Share via


Applications referencing both WPF and WinForms must disambiguate MenuItem and ContextMenu types

This document describes a breaking change introduced in .NET 10 Preview 1. Applications that reference both Windows Presentation Foundation (WPF) and Windows Forms (WinForms) must disambiguate certain types, such as MenuItem and ContextMenu, to avoid compile-time errors.

Version introduced

.NET 10 Preview 1

Previous behavior

Previously, the types ContextMenu, DataGrid, DataGridCell, Menu, MenuItem, ToolBar, and StatusBar would resolve to the System.Windows.Controls namespace because they did not exist in the System.Windows.Forms namespace in .NET Core 3.1 through .NET 9.0.

<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>

New behavior

The affected types in the System.Windows.Forms namespace cause a compile-time error when there is an ambiguous reference between System.Windows.Controls and System.Windows.Forms.

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

Type of breaking change

This is a source incompatible change.

Reason for change

The change facilitates migration from .NET Framework when third-party libraries cannot be updated. A .NET 10 application can continue to reference .NET Framework dependencies and handle errors at runtime.

Use aliases to resolve conflicting namespaces. For example:

using ContextMenu = System.Windows.Controls.ContextMenu;

Refer to the alias name conflicts documentation for more details.

Affected APIs