Failed to bind to address (already in use) error with Visual Studio Mac API

后端 未结 7 1715
隐瞒了意图╮
隐瞒了意图╮ 2021-01-21 03:34

I\'m attempting to create a Web API via .Net Core. I\'m just using the boilerplate ValuesController as a Hello World. When I run the project, I get the following error:

相关标签:
7条回答
  • 2021-01-21 03:59

    The port 5001 has already used in your system.

    Windows, use task manager to kill the processes "dotnet core host"

    Mac, force quit 'dotnet' in Activity Monitor app

    0 讨论(0)
  • 2021-01-21 04:01

    Assuming that you are using default port:

    this usually happens when a process gets corrupt and is disconnected from visual studio.

    If you are on mac, open activity monitor and kill the process by name "dotnet"

    If you are using a non standard port: then you need to change the port number to an available one. There is a solution from Amit on this thread, use that to change the port.

    0 讨论(0)
  • 2021-01-21 04:09

    The port 5001 has already used in your system. Change port number to 5002 or whatever you want.

    You can add port number with .UseUrls into CreateWebHostBuilder

      public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseUrls("http://localhost:5002")
                .UseStartup<Startup>();
    

    Or if you use visual studio code, just replace args section in .vscode -> launch.json.

    "args": ["urls=http://localhost:5002"]
    
    0 讨论(0)
  • 2021-01-21 04:11

    Got a similar Error on my project on port 5002 on Visual studio for MAC 2019, restarting Visual studio did nothing.

    i shutdown the machine and relaunched

    it's a safer solution i think.

    0 讨论(0)
  • 2021-01-21 04:12

    I know this is late answer. But it may be helpful to somebody.

    There seems a bug with MAC Visual Studio, it always goes https://127.0.0.1/5001.

    If you right click on your project, select options. Then Project Options Dialog will appear. On the left pane, goto Run->Configurations->Default, then on the right pane select ASP.Net Core tab. There is App URL which is being used by default. Change it to your needs.

    0 讨论(0)
  • 2021-01-21 04:17

    I was able to at least temporarily solve this issue by implementing a workaround provided by Bill Boga on his site here: https://www.billbogaiv.com/posts/setting-aspnet-host-address-in-net-core-2

    The key for my project was to add .UseUrls(urls: "http://localhost:10000") in the BuildWebHost function. Like so:

    using Microsoft.AspNetCore;
    using Microsoft.AspNetCore.Hosting;
    using OrchardCore.Logging;
    using OrchardCore.Modules;
    
    namespace ShiftBrandSite
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                BuildWebHost(args).Run();
            }
    
            public static IWebHost BuildWebHost(string[] args) =>
                WebHost.CreateDefaultBuilder(args)
                    .UseNLogWeb()
                    .UseStartup<Startup>()
                    .UseUrls(urls: "http://localhost:10000") // <-- localhost urls
                    .Build();
        }
    }
    

    Hope this helps!

    0 讨论(0)
提交回复
热议问题