How to solve a crossdomain policy security exception in C#
I have been trying to create a C# IRC client, I've got everything working, and when connecting to some networks it throws a socket policy exception as follows:
System.Security.Securi开发者_如何学CtyException: Unable to connect, as no valid crossdomain policy was found at System.Net.Sockets.Socket.Connect_internal (IntPtr sock, System.Net.SocketAddress sa, System.Int32& error, Boolean requireSocketPolicyFile) [0x00000] in :0 at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP, Boolean requireSocketPolicy) [0x00000] in :0 at System.Net.Sockets.Socket.Connect (System.Net.EndPoint remoteEP) [0x00000] in :0 at System.Net.Sockets.TcpClient.Connect (System.Net.IPEndPoint remote_end_point) [0x00000] in :0 at system.Net.Sockets.TcpClient.Connect (System.Net.IPAddress[] ipAddresses, Int32 port) [0x00000] in :0
Here's the code I am using to connect:
//connect the client
client = new TcpClient(serverAddress, serverPort);
The moment it tries to connect to most IRC servers it throws that exception, but for some it doesn't, as you probably realize I need the client to connect to any irc server that allows it.
I have tried searching for solutions on Google but all it came up with was Silverlight exceptions, I am not using Silverlight. I've been trying to resolve this for a week with no luck, I've been programming for 8 years, and I am quite adept at solving problems, but this is beyond me so any help is appreciated.
Regards, Amy.
Have you tried running the assembly as an administrator? If that works then it's a security issue and you need to specify the permission your program requires. So, if "Run as Admin" works, check: http://msdn.microsoft.com/en-us/library/system.net.socketpermissionattribute%28v=VS.110%29.aspx
精彩评论