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

时间:2012-07-07 08:38:53

标签: c# visual-studio-2010

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

  

类型或命名空间名称“ComponentModel”不存在于   namespace'Matrix.System'类型或命名空间名称'ServiceProcess'   名称空间'Matrix.System'

中不存在

但是服务中会产生错误:

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

在服务设置项目中我得到了这个:

  

无法找到依赖'IONIC.ZLIB'(签名='EDBE51AD942A3F5C'   版本='1.9.1.5')程序集'Apache.NMS.ActiveMQ.dll'

NMS程序集已经在安装项目中,一切正常,直到我添加了Matrix.System程序集

2 个答案:

答案 0 :(得分:4)

您可以像这样“root”命名空间:

using global::System.ComponentModel;

(然后在代码中删除完全限定的引用。)

或者,如果确实想要使用完全限定的命名空间:

private global::System.ComponentModel.IContainer components = null;
private global::System.ServiceProcess.ServiceInstaller serviceInstaller;

这看起来与其他依赖问题无关。

我的猜测是你在同一个班级:

using Matrix;

否则我不认为它首先是一个问题。

答案 1 :(得分:1)

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

enter image description here

enter image description here