“System.Net.Dns.GetHostByName(string)”已过时,怎么改为最新的

tznuoxla 2012-11-19 04:46:23
下面这段话中:

CSharpCodeProvider csc = new CSharpCodeProvider();
ICodeCompiler icc = csc.CreateCompiler(); //设定编译器的参数
CompilerParameters cplist = new CompilerParameters();
cplist.GenerateExecutable = false;
cplist.GenerateInMemory = true;
cplist.ReferencedAssemblies.Add("System.dll");
cplist.ReferencedAssemblies.Add("System.XML.dll");
cplist.ReferencedAssemblies.Add("System.Web.Services.dll");
cplist.ReferencedAssemblies.Add("System.Data.dll");
//编译代理类

警告 1 “System.Net.Dns.GetHostByName(string)”已过时:“"GetHostByName is obsoleted for this type, please use GetHostEntry instead. http://go.microsoft.com/fwlink/?linkid=14202"” E:\INA_WebService\WebService\App_Code\Service.cs 174 46 E:\INA_WebService\WebService\

这个怎么修改为最新的方法
...全文
855 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
whoamjinxin 2015-07-20
  • 打赏
  • 举报
回复
为什么改完了获取到的是IPV6的地址,晕
bdmh 2012-11-19
  • 打赏
  • 举报
回复
.NET Framework 受以下版本支持:1.0、1.1 在 2.0 中过时(编译器警告) .NET Compact Framework 受以下版本支持:1.0 在 2.0 中过时(编译器警告)
蝶恋花雨 2012-11-19
  • 打赏
  • 举报
回复
版本太旧的问题。升级一下就OK 以下都可。 1:System.Net.Dns.GetHostEntry(Dns.GetHostName()).AddressList[0].ToString(); 2: //using System.Net; string hostName = System.Net.Dns.GetHostName(); this.textBox1.Text = hostName;//获取主机名称 System.Net.IPHostEntry ipEntry = System.Net.Dns.GetHostEntry(hostName); //Dns.GetHostByName(hostName); //ip地址列表 System.Net.IPAddress[] addr = ipEntry.AddressList; string IPAddress = addr[0].ToString(); this.textBox2.Text = IPAddress;
蝶恋花雨 2012-11-19
  • 打赏
  • 举报
回复
将GetHostByName换成GetHostEntry即可。
tznuoxla 2012-11-19
  • 打赏
  • 举报
回复
警告 2 “System.CodeDom.Compiler.CodeDomProvider.CreateCompiler()”已过时:“"Callers should not use the ICodeCompiler interface and should instead use the methods directly on the CodeDomProvider class. Those inheriting from CodeDomProvider must still implement this interface, and should exclude this warning or also obsolete this method."” E:\INA_WebService\WebService\App_Code\WebServiceOperation.cs 77 29 E:\INA_WebService\WebService\ 刚才那个错误贴错了

110,534

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧