在添加程序集引用后,命名空间中不存在“ComponentModel”类型或命名空间名称

3

我遇到了一个奇怪的问题,很难诊断。在将包含命名空间Matrix.System的程序集引用添加到Windows服务项目后,编译服务时出现以下错误:

命名空间'Matrix.System'中不存在类型或命名空间名为'ComponentModel'的名称,命名空间'Matrix.System'中不存在类型或命名空间名为'ServiceProcess'的名称。

这些错误是在服务中生成的:

private System.ComponentModel.IContainer components = null;
private System.ServiceProcess.ServiceInstaller serviceInstaller1;

在服务设置项目中,我遇到了以下问题:

无法找到程序集 'Apache.NMS.ActiveMQ.dll' 的依赖项 'IONIC.ZLIB' (Signature='EDBE51AD942A3F5C' Version='1.9.1.5')

NMS程序集已经在设置项目中,一切都正常工作,直到我添加了Matrix.System程序集。

2个回答

5
您可以这样“root”命名空间:
using global::System.ComponentModel;

(然后在您的代码中消除完全限定的引用。)
或者,如果你真的想使用完全限定的命名空间:
private global::System.ComponentModel.IContainer components = null;
private global::System.ServiceProcess.ServiceInstaller serviceInstaller;

这似乎与其他依赖关系问题无关。
我猜测在同一个类中你有:

using Matrix;

否则我本来就不会指望它成为问题。

谢谢您的回答。阅读您的答案让我意识到Matrix.System在某种程度上“掩盖”了System命名空间。将Matrix.System更改为其他名称并重新导入解决了问题。非常感谢。 - codebrane

2
您需要从Nuget管理包中安装system.componentmodel。 因为在Microsoft的引用或系统中都没有system.componentmodel。 请注意,它不支持框架2.0,至少需要.NET框架4.3。

enter image description here

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接