C# 自托管 Web - 另一个应用程序使用的 TCP 端口 (win10)

C# Self Hosted Web - TCP Port used by another application (win10)

在 Windows 10 1703 (15063.483)

中尝试使用自托管 webapi 应用程序时刚开始出现异常

VS2017:版本 15.2 (26430.15) 发布 VisualStudio.15.Release/15.2.0+26430.15

我在管理员模式下试过运行VS,结果和非管理员模式一样。 我的应用正在尝试使用 http://192.168.12.118:50231 该项目是一个 .NET 4.5 WPF 应用程序。

应用第一次失败后,我做了:

这是我使用的代码:

            HttpSelfHostConfiguration config = new HttpSelfHostConfiguration(new Uri("http://" + MyIP + ":" + MyPort));
            config.MaxReceivedMessageSize = Int32.MaxValue - 1000;
            config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always;              
            config.Routes.MapHttpRoute(
                name: "DefaultApi",
                routeTemplate: "{controller}/{action}/{id}",
                defaults: new { id = RouteParameter.Optional }
            );

            // Startup server 
            server = new HttpSelfHostServer(config);
            server.OpenAsync().Wait();          

这是我遇到的异常,当执行命中 OpenAsync 时:

.Inner Type: AddressAlreadyInUseException
.Inner Message: HTTP could not register URL http://+:50231/ because TCP port 50231 is being used by another application.
.Inner Stack:    at System.Runtime.AsyncResult.End[TAsyncResult](IAsyncResult result)
at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result)
at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)

 ..Inner Type: HttpListenerException
 ..Inner Message: The process cannot access the file because it is being    used by another process
 ..Inner Stack:    at System.Runtime.AsyncResult.End[TAsyncResult]    (IAsyncResult result)
   at System.ServiceModel.Channels.CommunicationObject.EndOpen(IAsyncResult result)
   at System.Web.Http.SelfHost.HttpSelfHostServer.OpenListenerComplete(IAsyncResult result)`

TIA

"Did you reboot?" 做到了。对我来说没有意义,因为没有列出任何使用该端口的东西......哦好吧。