0

我有一个名为 AAA.System 的项目,其中包含一些简单的基本功能,可供我们所有其他项目共享。这已经存在了大约 5 年左右,我们有许多引用它的项目都运行良好。

现在,我正在创建一个新项目(WCF 服务),但在命名空间解析方面遇到了一些问题。具体来说,我有这些用途:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Configuration;
using System.Configuration.Install;
using System.Reflection;
using System.ServiceModel;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using System.Xml;

在某些时候,我有这行代码:

string fqdn = System.Net.Dns.GetHostName();

这是产生错误:

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

因此,视觉工作室(2010)似乎以某种方式试图解决AAA.System.Net.Dns.GetHostName()而不是System.Net.Dns.GetHostName(),但我没有任何使用语句表明使用AAA.System. 我在这里缺少什么指示编译器使用 AAA.System?

4

1 回答 1

0

您正在调用以下行的类的名称空间是否设置为AAA

string fqdn = System.Net.Dns.GetHostName(); 

例如

namespace AAA
{
    static void M()
    {
        string fqdn = System.Net.Dns.GetHostName(); 
    }
}

要修复它,您应该能够在该行前加上global::.

string fqdn = global::System.Net.Dns.GetHostName(); 

或者只是System.Net使用指令添加到您

于 2012-05-16T16:25:40.040 回答