diff --git a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs index c50ca5462..a18bbc7f9 100644 --- a/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs +++ b/src/WireMock.Net/Owin/AspNetCoreSelfHost.cs @@ -56,7 +56,18 @@ public AspNetCoreSelfHost([NotNull] IWireMockMiddlewareOptions options, [NotNull public Task StartAsync() { - _host = new WebHostBuilder() + var builder = new WebHostBuilder(); + + // Workaround for https://github.com/WireMock-Net/WireMock.Net/issues/292 + // On some platforms, AppContext.BaseDirectory is null, which causes WebHostBuilder to fail if ContentRoot is not + // specified (even though we don't actually use that base path mechanism, since we have our own way of configuring + // a filesystem handler). + if (string.IsNullOrEmpty(AppContext.BaseDirectory)) + { + builder.UseContentRoot(System.IO.Directory.GetCurrentDirectory()); + } + + _host = builder .ConfigureServices(services => { services.AddSingleton(_options.FileSystemHandler);