【问题标题】:Nancy Self-Hosted RunTimeBinderExceptionNancy 自托管 RunTimeBinderException
【发布时间】:2016-04-15 21:23:46
【问题描述】:

我正在尝试在 .NET 4.6.1(Visual Studio 2015 Update 2)中使用 Nancy。当我根据下面的代码和参考创建引用 .NET 4.6.1 框架的控制台应用程序时,我在自己的示例 StubNancy.Response 之间看到了一个 Microsoft.CSharp.RuntimeBinder.RuntimeBinderException,但从未收到任何 JSON 输出。 Super-Duper-Happy-Path 中是否缺少我的东西?我知道我没有指定视图,但我只是打算使用以下接受标头调用此资源:Accept: application/json。我以“管理员”身份执行 Visual Studio,操作系统是 Windows 7 x64(大部分是最新更新)。

程序.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();
        }
    }
}

参考资料:

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

我的最终目标是将其放入带有 websockets 的 OWIN 自托管模块中,但我将其剥离回此示例以尝试隔离我的问题。

【问题讨论】:

    标签: c# nancy .net-4.6.1


    【解决方案1】:

    我正在使用带有 Accept: application/json 自定义标头的 HAL 浏览器(下载到我的文件系统中),但从未收到响应。我切换到 Fiddler,它现在按预期工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-16
      • 1970-01-01
      • 1970-01-01
      • 2017-07-30
      • 1970-01-01
      • 1970-01-01
      • 2011-09-22
      • 1970-01-01
      相关资源
      最近更新 更多