I'm trying to start up a WebApp to use with NancyFx in a .NET Core 2.0 project.
The package i've added to the solution to do this is
Microsoft.AspNet.WebApi.OwinSelfHost
which installs it's dependencies:
Microsoft.AspNet.WebApi.Client
Microsoft.AspNet.WebApi.Core
Microsoft.AspNet.WebApi.Owin
Microsoft.Owin
Microsoft.Owin.Host.HttpListener
Microsoft.Owin.Hosting
Newtonsoft.Json
Owin
I've also added:
Nancy
Nancy.Owin
My project is of type "xUnit Test Project (.NET Core)".
Starting with my test class, we have:
public class MyIntegrationTests : IDisposable
{
private readonly IDisposable _webApp;
private const string Url = "http://localhost:1234";
public MyIntegrationTests()
{
_webApp = WebApp.Start<Startup>(url: Url);
}
My startup class looks like:
public class Startup
{
public void Configuration(IAppBuilder appBuilder)
{
appBuilder.UseNancy();
}
}
I also have a NancyModule with a test route:
public class TestModule : NancyModule
{
public TestModule()
{
Get("/test", args => "test");
}
}
However, when starting my Integration Tests module (by trying to run any test within it), i am met with a Null Reference Exception. This is the stack trace:
System.NullReferenceException : Object reference not set to an instance of an object.
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.FromConfigImplementation..ctor()
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.b__0() at System.Threading.LazyInitializer.EnsureInitializedCore[T](T& target, Func`1 valueFactory)
at Microsoft.Owin.Hosting.Utilities.SettingsLoader.LoadFromConfig(IDictionary`2 settings)
at Microsoft.Owin.Hosting.Engine.StartContext..ctor(StartOptions options)
at Microsoft.Owin.Hosting.Starter.DirectHostingStarter.Start(StartOptions options)
at Microsoft.Owin.Hosting.Starter.HostingStarter.Start(StartOptions options)
at [redacted].IntegrationTests.MyIntegrationTests..ctor() in C:\Users[redacted]\source\repos[redacted].IntegrationTests\MyIntegrationTests.cs:line 21
What i've tried:
- Adding packages one by one, with varying versions.
- Changing my Startup Class to add a HttpConfiguration
- Clearing localhost cookies (was suggested in other topics here)
- Using this guide: https://github.com/NancyFx/Nancy/wiki/Hosting-nancy-with-owin#katana---httplistener-selfhost i receive the exact same error as previously.
To me, it looks like there is a configuration missing - or not being found. However, everything i refer to exists. Any ideas? (Worth mentioning - this test project has no appsettings.json, web.config, etc)
EDIT: Test project available here: https://www.dropbox.com/s/v1bw5pu9t0e9fwt/NancyOwinTest.zip?dl=0 Making the test project, i realise it's restoring packages at the .NET 4.6.1 level, rather than .NET Core. I may well be making a stupid mistake, but which one, i haven't figured out yet.