1

I have the following OWIN implementation to run my functional tests on CI

    protected const string Url = "http://localhost:8785";
    private static IDisposable _app;

    Establish context = () => _app = WebApp.Start(Url, a =>
    {
        a.Use(typeof(MockIdentityMiddleware));
        new Startup().Configuration(a);
    });

    Cleanup after = () => _app.Dispose();

But when it runs I get the following stack trace:

System.Net.HttpListenerException: Failed to listen on prefix 'http://localhost:8785/' because it conflicts with an existing registration on the machine.

I want to remove the registration for that port programmatically so I don't have to worry anymore but not sure how to do it with Owin.

Rober
  • 726
  • 8
  • 27

1 Answers1

1

You should not hard code port number in your test, as you can never be sure if the port is free or not.

There is quite simple code that allows to find next free TCP port on a given machine https://stackoverflow.com/a/150974/295582

Community
  • 1
  • 1
Nikita Skvortsov
  • 4,768
  • 24
  • 37