简体   繁体   English

HttpListener在发布模式下崩溃

[英]HttpListener Crashes in Release mode

To recreate the issue 重现问题
1. Create a Android application 1.创建一个Android应用程序
2. Install Nito.AsyncEx.Context 2.安装Nito.AsyncEx.Context
3. Add the code below 3.添加以下代码
4. Set release mode 4.设置释放模式
5. Deploy code 5.部署代码
6. Start the app (and watch it burn! it crashes on both my 10.1" Marshmallow... emulator and a Samsung Galaxy Note 10.1 ) 6.启动应用程序(并观看它燃烧!它在我的10.1" Marshmallow...模拟器和Samsung Galaxy Note 10.1上都崩溃)

using Android.App;
using Android.Widget;
using Android.OS;
using System.Threading.Tasks;
using System.Net;
using System.Text;
using Nito.AsyncEx;

namespace App1
{
    [Activity(Label = "App1", MainLauncher = true, Icon = "@drawable/icon")]
    public class MainActivity : Activity
    {
        private readonly HttpListener listener = new HttpListener();

        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);
            var thread = new System.Threading.Thread(RunThread);
            thread.Start();
        }

        void RunThread()
        {
            AsyncContext.Run(() => Run()); //Exception in release mode
            //Task.Run(Run); //Silent exception in release mode
        }

        protected async Task Run()
        {
            listener.Prefixes.Add("http://localhost:8082/");
            listener.Start();
            while (true)
            {
                var context = await listener.GetContextAsync();
                var data = Encoding.UTF8.GetBytes("<html><body>Hello world</body></html>");
                context.Response.OutputStream.Write(data, 0, data.Length);
                context.Response.Close();
            }
        }
    }
}

I get the following exception: 我得到以下异常:

E/mono    (29964): Unhandled Exception:
E/mono    (29964): System.Net.Sockets.SocketException (0x80004005): mono-io-layer-error (10013)
E/mono    (29964):   at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00069] in <12894373fb4d403880bd3e387a4ef038>:0
E/mono    (29964):   at System.Net.EndPointListener..ctor (System.Net.HttpListener listener, System.Net.IPAddress addr, System.Int32 port, System.Boolean secure) [0x0003b] in <12894373fb4d403880bd3e387a4ef038>:0
E/mono    (29964):   at System.Net.EndPointManager.GetEPListener (System.String host, System.Int32 port, System.Net.HttpListener listener, System.Boolean secure) [0x0009d] in <12894373fb4d403880bd3e387a4ef038>:0
E/mono    (29964):   at System.Net.EndPointManager.AddPrefixInternal (System.String p, System.Net.HttpListener listener) [0x0005e] in <12894373fb4d403880bd3e387a4ef038>:0
E/mono    (29964):   at System.Net.EndPointManager.AddListener (System.Net.HttpListener listener) [0x0009c] in <12894373fb4d403880bd3e387a4ef038>:0
E/mono    (29964):   at System.Net.HttpListener.Start () [0x0000f] in <12894373fb4d403880bd3e387a4ef038>:0
...

To open a socket, your application needs the INTERNET permission. 要打开套接字,您的应用程序需要INTERNET权限。 Add the following line to your AndroidManifest.xml file: AndroidManifest.xml下行添加到您的AndroidManifest.xml文件中:

<uses-permission android:name="android.permission.INTERNET" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 UWP-WebAuthenticationBroker在发布模式下在设备上崩溃 - UWP - WebAuthenticationBroker crashes on device in release mode Xamarin Monogame 应用程序在启动时在发布模式下崩溃 - Xamarin Monogame app crashes in release mode on startup 发布模式 UWP 应用程序在平板电脑模式下和 OnSuspended 中的代码崩溃 - Release mode UWP app crashes when in tablet mode and with code in OnSuspended 应用程序在发布模式下崩溃,而不是在调试模式下崩溃 - Xamarin Forms - App crashes in release mode and not in debug mode - Xamarin Forms 在调试模式下运行的同一Android应用程序在发布模式下崩溃 - Same Android app who runs on Debug mode, crashes on release mode Xamarin PCL Android 应用程序在发布模式下突然崩溃 - Xamarin PCL Android app suddenly crashes in release mode C#HttpHandler崩溃了IIS - 但仅在发布模式下进行了优化 - C# HttpHandler crashes IIS - but only in Release mode with optimizations on UWP XAMARIN在RELEASE模式下崩溃(但在调试中运行良好) - UWP XAMARIN crashes in RELEASE mode (but good working in debug) HTTPListener在四核机器Win 2008 Server R2上崩溃 - HTTPListener crashes on quad core machine Win 2008 Server R2 在发布配置中随机崩溃 - Randomly crashes in release configuration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM