Mono说"System.Net.Dns.GetHostEntry(string)"由于其保护级别而无法访问

编程入门 行业动态 更新时间:2024-10-24 22:29:03
本文介绍了Mono说"System.Net.Dns.GetHostEntry(string)"由于其保护级别而无法访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我现在正在上课,其中一些示例在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.

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

#if NET_2_0 public #else internal #endif static IPHostEntry GetHostEntry (string hostNameOrAddress) { // ...

更多推荐

Mono说"System.Net.Dns.GetHostEntry(string)"由于其保护级别而无法访问

本文发布于:2023-11-12 04:37:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580523.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:于其   无法访问   级别   System   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!