【发布时间】:2017-12-13 12:11:14
【问题描述】:
我的代码:
public class MyWebService : IDisposable
{
private readonly NancyHost _host;
public MyWebService(int port = 7017)
{
var uri = new Uri(string.Format("http://localhost:{0}", port));
_host = new NancyHost(uri);
_host.Start();
}
public void Dispose()
{
if (_host != null)
{
_host.Stop();
_host.Dispose();
}
}
}
internal class MyWebModule : NancyModule
{
public MyWebModule()
{
Get["/"] = _ => "Received GET request";
}
}
当运行以下 HTTP 请求时:GET http://localhost:7017/ 使用 Insomnia REST client,我得到以下神秘异常:
Microsoft.CSharp.RuntimeBinder.RuntimeBinderException: 'Cannot convert type 'Nancy.ErrorHandling.DefaultStatusCodeHandler.DefaultStatusCodeHandlerResult' to 'Nancy.Response''
at CallSite.Target(Closure , CallSite , Object )
来源:Anonymously Hosted DynamicMethods Assembly
跟进
Nancy.ViewEngines.ViewNotFoundException
at Nancy.ViewEngines.DefaultViewFactory.GetRenderedView(String viewName, Object model, ViewLocationContext viewLocationContext)
没有任何关于异常的额外信息。
REST 客户端随后显示错误404。
我定义错了什么?我遵循了以下示例:building-a-simple-http-server-with-nancy
【问题讨论】:
标签: c# httpresponse nancy httpserver viewengine