C# 命名空间“系统”中不存在类型或命名空间名称“Windows”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14641224/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-10 12:32:56  来源:igfitidea点击:

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

c#asp.net-mvc-3

提问by blue

I am trying to code for pop up message box for displaying message for successful record insertion in C#.net

我正在尝试编写弹出消息框的代码,以便在 C#.net 中显示成功插入记录的消息

Error:

错误

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

命名空间“System”中不存在类型或命名空间名称“Windows”(您是否缺少程序集引用?)

Code:

代码

 global::System.Windows.Forms.MessageBox.Show("Test");

采纳答案by meda

You are not missing any DLL , It seems like you are using the wrong type of project.

您没有丢失任何 DLL ,您似乎使用了错误类型的项目。

回答by Darin Dimitrov

global::System.Windows.Forms.MessageBox.Show("Test");in an ASP.NET MVC application? And where did you expect this message box to pop out?

global::System.Windows.Forms.MessageBox.Show("Test");在 ASP.NET MVC 应用程序中?你期望这个消息框在哪里弹出?

In an ASP.NET MVC application you could use client side javascript to show message boxes.

在 ASP.NET MVC 应用程序中,您可以使用客户端 javascript 来显示消息框。

For example inside your view you could put the following:

例如在您的视图中,您可以输入以下内容:

<script type="text/javascript">
    alert('Test');
</script>

And when you navigate to the corresponding controller action the user will be greeted with the message box.

当您导航到相应的控制器操作时,用户将看到消息框。

回答by Dmytro Dzyubak

If you are using MS Visual Studio:

如果您使用的是 MS Visual Studio:

  1. Right click on the Project
  2. Select "Add Reference..."
  3. Navigate to the ".NET" tab
  4. Find "System.Windows.Forms" and select it
  5. Click OK.
  1. 右键单击项目
  2. 选择“添加引用...”
  3. 导航到“.NET”选项卡
  4. 找到“System.Windows.Forms”并选择它
  5. 单击确定。

P. S.: Additionally, I had to do the same with "System.Drawing" for everything to work correctly in my first GUI Windows program.

PS:此外,我必须对“System.Drawing”做同样的事情,才能在我的第一个 GUI Windows 程序中正常工作。

回答by Vivek Arkalgud

I am using Visual Studio 2012, Framework 4.0 for windows application. I was also getting the following message: 'the type or namespace 'windows' does not exist'

我正在为 Windows 应用程序使用 Visual Studio 2012、Framework 4.0。我还收到以下消息:“类型或命名空间‘windows’不存在”

To fix this problem, I added reference to Windows.Forms.dll. After that I can display message box using the following code

为了解决这个问题,我添加了对 Windows.Forms.dll 的引用。之后,我可以使用以下代码显示消息框

System.Windows.Forms.MessageBox.Show("Completed successfully");

System.Windows.Forms.MessageBox.Show("完成成功");

回答by Andy Reed

Incredibly I got this error when one of my class libraries has 'System' in its own namespace. MyCompany.Foo.Bar.Client.System as my assembly namespace must have cause a clash somewhere. Removing the 'System' from my namespace solved the problem.

令人难以置信的是,当我的一个类库在其自己的命名空间中具有“系统”时,我收到了此错误。MyCompany.Foo.Bar.Client.System 作为我的程序集命名空间必须在某处引起冲突。从我的命名空间中删除“系统”解决了这个问题。