Search code examples
c#nancy.net-4.6.1

Nancy Self-Hosted RunTimeBinderException


I'm trying to use Nancy in .NET 4.6.1 (Visual Studio 2015 Update 2). When I create a console app that references the .NET 4.6.1 Framework based on the code & references below, I see a Microsoft.CSharp.RuntimeBinder.RuntimeBinderException between my own example Stub and Nancy.Response while never receiving any JSON output. Is there something I'm missing from the Super-Duper-Happy-Path? I understand that I haven't specified a view, but I'm only intending to call this resource using an accept header of: Accept: application/json. I'm executing Visual Studio as 'Administrator' and the OS is Windows 7 x64 (with mostly the latest updates).

Program.cs:

using System;

namespace SelfHostedTest
{
    class Program
    {
        static void Main(string[] args)
        {
            var host = new SelfHoster();

            host.Create("http://localhost:8002");
            Console.WriteLine("Started");
            Console.ReadLine();

            host.Destroy();
        }
    }
}

RootModule.cs:

using Nancy;

namespace SelfHostedTest
{
    public class Stub
    {
        public int Number { get; set; }
        public string Message { get; set; }
    }

    public class RootModule : NancyModule
    {
        public RootModule()
        {
            Get["/"] = _ => new Stub() {Message = "Hello", Number = 1};
        }
    }
}

SelfHoster.cs:

using System;
using Nancy;
using Nancy.Hosting.Self;

namespace SelfHostedTest
{
    public class SelfHoster
    {
        private NancyHost _host;
        public void Create(string url)
        {
            _host = new NancyHost(new Uri(url), new DefaultNancyBootstrapper());
            _host.Start();
        }

        public void Destroy()
        {
            _host?.Stop();
        }
    }
}

References:

Microsoft.CSharp
Nancy (1.4.3)
Nancy.Hosting.Self (1.4.1)
Nancy.Serialization.JsonNet (1.4.1)
Newtonsoft.Json (8.0.3)
System
System.Core
System.Data
System.Data.DataSetExtensions
System.Net.Http
System.Xml
System.Xml.Linq

My ultimate goal is to put this in an OWIN self-hosted module with websockets but I stripped it back to this example to try and isolate my issue.


Solution

  • I was using the HAL browser (downloaded onto my filesystem) with a custom header of Accept: application/json but never received a response. I switched to Fiddler and it is now working as expected.