Mono说"System.Net.Dns.GetHostEntry(string)"由于其保护级别而无法访问 [英] Mono says 'System.Net.Dns.GetHostEntry(string)' is inaccessible due to its protection level
问题描述
我现在正在上课,其中一些示例在C#中进行.由于笔记本电脑运行Linux,因此我在Ubuntu上使用Mono 2.6.7.
I'm taking a class right now where some of the examples are in C#. Since my laptop runs Linux, I'm using Mono 2.6.7 on Ubuntu.
我正在尝试编译以下代码:
I'm trying to compile the following code:
using System.Net.Sockets;
using System.Net;
using System;
/// <summary>
/// Example program showing simple TCP socket connections in C#.NET.
/// Rather than reading and writing byte arrays, this example show
/// how to use a stream reader in the client.
/// TCPSocketServer is the socket server.
/// <author>Tim Lindquist ASU Polytechnic Department of Engineering</author>
/// <version>September, 2009</version>
/// </summary>
public class TCPSocketServer {
public static void Main (string [] args) {
IPAddress ipAddress = Dns.GetHostEntry("localhost").AddressList[0];
TcpListener tcpl = new TcpListener(ipAddress, 9090);
tcpl.Start();
Console.WriteLine("TCPSocketServer waiting for connections on 9090");
Socket sock = tcpl.AcceptSocket();
string msg = "Hello Client";
Byte[] msgBytes = System.Text.Encoding.ASCII.GetBytes(msg);
sock.Send(msgBytes, msgBytes.Length, SocketFlags.DontRoute);
Console.WriteLine("Message-Hello Client-sent to client.");
tcpl.Stop();
sock.Close();
}
}
编译代码时,我得到:
/home/vivin/Projects/cst420/CSSockets/src/TCPSocketServer.cs(16,31): error CS0122: `System.Net.Dns.GetHostEntry(string)' is inaccessible due to its protection level
/usr/lib/mono/gac/System/1.0.5000.0__b77a5c561934e089/System.dll (Location of the symbol related to previous error)
ompilation failed: 1 error(s), 0 warnings
我是C#新手;这是我编译过的第一个C#程序.我尝试在Google上进行搜索,但针对该问题的点击率并不高. Mono有问题吗?
I'm a C# novice; this is the first C# program I've ever compiled. I tried searching on Google, but I didn't get very many hits for this problem. Is this a problem with Mono?
推荐答案
.NET Framework 2.0 中引入了"nofollow noreferrer> System.Net.Dns.GetHostEntry .在Mono的实现中,它也存在于2.0之前的版本中,但标记为internal
而不是public
.您似乎正在针对 .NET Framework 1.0 进行编译.
System.Net.Dns.GetHostEntry was introduced in the .NET Framework 2.0. In Mono's implementation, it's also present in the pre-2.0 versions, but marked as internal
instead of public
. You seem to be compiling against the .NET Framework 1.0.
来自 查看全文