命名空间 'System.Windows' 中不存在类型或命名空间名称 'Forms'

The type or namespace name 'Forms' does not exist in the namespace 'System.Windows'

我需要selectjson文件。

public void LoadChartData()
{
   var ofDialog = new System.Windows.Forms.OpenFileDialog { Filter = @"json (*.json)|*.json" };
   if (ofDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
   { }
}

不幸的是,此代码的编译 returns 错误(两次,每个 System.Windows.Forms ):

Error   CS0234  The type or namespace name 'Forms' does not exist in the namespace 'System.Windows' (are you missing an assembly reference?)    

如何处理这个错误?

在您的项目中包含 System.Windows.Forms 程序集(如错误消息所建议的那样)。

转到您的解决方案资源管理器,右键单击您的项目。然后单击 添加引用 。选择 System.Windows.Forms 并点击 确定