Skip to content

Nancy.Hosting.Self.AutomaticUrlReservationCreationFailureException' occurred in Nancy.Hosting.Self.dll when running NancyFx Self Hosted template

I was getting this error while using the NancyFx SideWaffle templates for Visual Studio

Basically the code from the template is shown below

static void Main(string[] args)
        {
            var uri =
                new Uri("http://localhost:3579");


            using (var host = new NancyHost(uri))
            {
                host.Start();

                Console.WriteLine("Your application is running on " + uri);
                Console.WriteLine("Press any [Enter] to close the host.");
                Console.ReadLine();
            }
        }

What needs to be changed is shown below

static void Main(string[] args)
        {
            var uri = 
                    new Uri("http://localhost:3579");

            HostConfiguration hostConfigs = new HostConfiguration()
            {
                UrlReservations = new UrlReservations() { CreateAutomatically = true}
            };

            using (NancyHost host = new NancyHost(uri, new DefaultNancyBootstrapper(), hostConfigs))
            {
                host.Start();

                Console.WriteLine("Your application is running on "+ uri);
                Console.WriteLine("Press any [Enter] to close the host.");
                Console.ReadLine();
            }
        }

Posted in Development