Reputation: 3611
im doing client and server socket communication in c# but i got this error..
Error: Request for the permission of type 'System.Net.DnsPermission,
System, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed.
what is the posibility for this error.. i run my application using another machine but it seems ok.. this error comes out when i use Windows SP3 with the latest .Net
i think the reason is im using a deprecated syntax in .Net
IPAddress IPAddress = Dns.GetHostByName(Dns.GetHostName()).AddressList[0];
for getting the machine IPAddress.. is there another syntax for doing this? which is not deprecated..? i googled it and tried some blocks of code but IPAddress return IPV6 IP type.. :D
any help please.. :)
Upvotes: 1
Views: 1152
Reputation: 17701
Did you try this..
using System.Net;
string host = Dns.GetHostName();
IPHostEntry ip = Dns.GetHostEntry(host);
Console.WriteLine(ip.AddressList[0].ToString());
Upvotes: 2