コンパイル時エラーを回避するために、Windows Presentation Foundation (WPF) と Windows フォーム (WinForms) の両方を参照するアプリケーションでは、 MenuItem や ContextMenuなど、特定の型を明確にする必要があります。
導入されたバージョン
.NET 10
以前の動作
以前は、ContextMenu、DataGrid、DataGridCell、Menu、MenuItem、ToolBar、StatusBarの型は、.NET Core 3.1 から .NET 9.0 のSystem.Windows.Controls名前空間に存在しなかったため、System.Windows.Forms名前空間に解決されました。
<ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
<UseWPF>true</UseWPF>
新しい動作
System.Windows.Forms名前空間の影響を受ける型は、System.Windows.ControlsとSystem.Windows.Formsの間にあいまいな参照がある場合にコンパイル時エラーが発生します。
CS0104 'ContextMenu' is an ambiguous reference between 'System.Windows.Controls.ContextMenu' and 'System.Windows.Forms.ContextMenu'
破壊的変更の種類
これは、ソースの互換性のない 変更です。
変更の理由
この変更により、サード パーティ製ライブラリを更新できない場合に、.NET Framework からの移行が容易になります。 .NET 10 アプリケーションは、.NET Framework の依存関係を引き続き参照し、実行時にエラーを処理できます。
推奨されるアクション
エイリアスを使用して、競合する名前空間を解決します。 例えば次が挙げられます。
using ContextMenu = System.Windows.Controls.ContextMenu;
詳細については、 エイリアス名の競合に関するドキュメント を参照してください。
影響を受ける API
- System.Windows.Forms.ContextMenu
- System.Windows.Forms.DataGrid
- System.Windows.Forms.DataGridCell
- System.Windows.Forms.Menu
- System.Windows.Forms.MenuItem
- System.Windows.Forms.ToolBar
- System.Windows.Forms.StatusBar
- System.Windows.Controls.ContextMenu
- System.Windows.Controls.DataGrid
- System.Windows.Controls.DataGridCell
- System.Windows.Controls.Menu
- System.Windows.Controls.MenuItem
- System.Windows.Controls.ToolBar
System.Windows.Controls.StatusBar
.NET