首页 > 开发 > 综合 > 正文

展现C# 清单5.10 生成exe文件执行的问题

2024-07-21 02:16:04
字体:
来源:转载
供稿:网友

清单  5.10  通过一个索引获取一个ip地址

1: using system;
2: using system.net;
3:
4: class resolvedns
5: {
6:  ipaddress[] m_arrips;
7:
8:  public void resolve(string strhost)
9:  {
10:  iphostentry iphe = dns.gethostbyname(strhost);
11:  m_arrips = iphe.addresslist;
12:  }
13:
14:  public ipaddress this[int nindex]
15:  {
16:  get
17:  {
18:    return m_arrips[nindex];
19:  }
20:  }
21:
22:  public int count
23:  {
24:  get { return m_arrips.length; }
25:  }
26: }
27:
28: class dnsresolverapp
29: {
30:  public static void main()
31:  {
32:  resolvedns mydnsresolver = new resolvedns();
33:  mydnsresolver.resolve("http://www.microsoft.com");
34:
35:  int ncount = mydnsresolver.count;
36:  console.writeline("found {0} ip's for hostname", ncount);
37:  for (int i=0; i < ncount; i++)
38:    console.writeline(mydnsresolver[i]);
39:  } 
40: }

编译环境:

 visual studio .net2003 version 7.1.3091  microsoft visual c# .net  

 microsoft .net framework version 1.1.4322 sp1

生成的exe文件,执行后报错:

未处理的“system.net.sockets.socketexception”类型的异常出现在 system.dll 中。

其他信息: the requested name is valid and was found in the database, but it does not have the correct associated data being resolved for

这是为什么呢?……
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表