代码之家  ›  专栏  ›  技术社区  ›  Vivin Paliath

莫诺说系统.Net.Dns.GetHostEntry(字符串)由于其保护级别而不可访问

  •  3
  • Vivin Paliath  · 技术社区  · 14 年前

    我现在正在上一节课,其中一些例子是用C#。因为我的笔记本电脑运行Linux,所以我在Ubuntu上使用的是Mono 2.6.7。

    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上搜索,但是这个问题没有得到太多的点击。这是单声道的问题吗?

    2 回复  |  直到 14 年前
        1
  •  7
  •   dtb    14 年前

    System.Net.Dns.GetHostEntry 是在 .NET Framework 2.0 . 在Mono的实现中,它也出现在2.0之前的版本中,但标记为 internal 而不是 public . 你好像在反对 .

    /mcs/class/System/System.Net/Dns.cs :

    #if NET_2_0
        public
    #else
        internal
    #endif
        static IPHostEntry GetHostEntry (string hostNameOrAddress)
        {
            // ...
    
        2
  •  5
  •   Gabriel Burt    14 年前

    你在用那个吗 gmcs 编译器?