繁体   English   中英

剃须刀自托管南希返回空的身体

[英]Self hosting nancy with razor returns empty body

带有剃刀的自托管南希返回空的身体。

我正在尝试在带有剃刀视图的控制台应用程序中自托管nancy,但是我又回来了。 在IIS中运行时,它确实可以工作。

我做了什么:

  • 我将所有适当的剃刀配置添加到App.Config中并构建了提供程序
  • 我添加了一个自定义的静态根路径提供程序,它似乎配置正确,因为可以无问题地提供静态文件:

     protected override IRootPathProvider RootPathProvider { get { if (ConfigurationManager.AppSettings["RootPath"].HasValue()) { var path = Path.Combine(new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.FullName, ConfigurationManager.AppSettings["RootPath"]); return new StaticRootPathProvider(path); } return new DefaultRootPathProvider(); } } 
  • 剃刀视图被发现正在编译,因为当我向视图添加无效代码时,确实出现了剃刀编译器错误

  • 当我调试时捕获了所有异常时,在投放页面时出现异常:

Nancy.dll中发生类型为“ Microsoft.CSharp.RuntimeBinder.RuntimeBinderException”的第一次机会异常

附加信息:无法将类型“ Nancy.Responses.Negotiation.Negotiator”转换为“ Nancy.Response”

Nancy.dll!Nancy.Routing.DefaultRouteInvoker.CastResultToResponse(动态结果)未知Nancy.dll!Nancy.Routing.DefaultRouteInvoker.InvokeRouteWithStrategy(动态结果,Nancy.NancyContext上下文)未知Nancy.dll!Nancy.Routing.DefaultRouteInvoker.Invoke.AnonymousMethod__5 (System.Threading.Tasks.TaskcompletedTask)未知Nancy.dll!Nancy.Helpers.TaskHelpers.WhenCompleted(System.Threading.Tasks.Task任务,System.Action> onComplete,System.Action> onFaulted,bool execSync)未知Nancy。 dll!Nancy.Routing.DefaultRouteInvoker.Invoke(Nancy.Routing.Route路由,System.Threading.CancellationToken取消令牌,Nancy.DynamicDictionary参数,Nancy.NancyContext上下文)未知Nancy.dll!Nancy.Routing.DefaultRequestDispatcher.Dispatch.AnonymousMethod__0(系统.Threading.Tasks.TaskcompletedTask)未知的Nancy.dll!Nancy.Helpers.TaskHelpers.WhenCompleted(System.Threading.Tasks.Task任务,System.Action> onComplete,System.Action> onFaulted,bool execSync)未知的Nancy.dll! Nancy.Ro uting.DefaultRequestDispatcher.Dispatch(Nancy.NancyContext上下文,System.Threading.CancellationToken cancellingToken)未知Nancy.dll!Nancy.NancyEngine.InvokeRequestLifeCycle.AnonymousMethod__9(System.Threading.Tasks.Task t)未知Nancy.dll!Nancy.Helpers.TaskHelpers .WhenCompleted(System.Threading.Tasks.Task任务,System.Action> onComplete,System.Action> onFaulted,bool execSync)未知Nancy.dll!Nancy.NancyEngine.InvokeRequestLifeCycle(Nancy.NancyContext上下文,System.Threading.CancellationToken cancelledToken, Nancy.Bootstrapper.IPipelines管道)未知Nancy.dll!Nancy.NancyEngine.HandleRequest(Nancy.Request请求,System.Func preRequest,System.Threading.CancellationToken cancellingToken)未知Nancy.dll!Nancy.NancyEngineExtensions.HandleRequest(Nancy.INancyEngine nancyEngine ,Nancy.Request请求,System.Func preRequest)未知Nancy.dll!Nancy.NancyEngineExtensions.HandleRequest(Nancy.INancyEngine nancyEngine,Nancy.Request请求)未知Nancy.Hosting。 Self.dll!Nancy.Hosting.Self.NancyHost.Process(System.Net.HttpListenerContext ctx)未知Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.GotCallback(System.IAsyncResult ar)未知System.dll! System.Net.LazyAsyncResult.Complete(System.IntPtr userToken)未知System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,System.IntPtr userToken)未知System.dll!System.Net.ListenerAsyncResult.IOCompleted(System.Net .ListenerAsyncResult asyncResult,uint errorCode,uint numBytes)未知System.dll!System.Net.ListenerAsyncResult.WaitCallback(uint errorCode,uint numBytes,System.Threading.NativeOverlapped * nativeOverlapped)未知mscorlib.dll! uint errorCode,uint numBytes,System.Threading.NativeOverlapped * pOVERLAP)未知

然后是ArgumentNullException:

发生System.ArgumentNullException消息:System.Web.dll中发生了类型为'System.ArgumentNullException'的第一次机会异常。其他信息:值不能为null。

System.Web.dll!System.Web.HttpContextWrapper.HttpContextWrapper(System.Web.HttpContext httpContext)未知System.Web.Optimization.dll!System.Web.Optimization.Styles.Context.get()未知System.Web.Optimization。 dll!System.Web.Optimization.Styles.RenderFormat(字符串tagFormat,字符串[]路径)未知Temp_bfd13a3e77214eca9b1ce8f1a37d244d.dll!RazorOutput.RazorView.Execute()未知Nancy.ViewEngines.Razor.dll!Nancy.ViewEngines.Razor.Nancy (字符串体,System.Collections.Generic.IDictionary部分内容)未知[轻量级函数]
Nancy.ViewEngines.Razor.dll!Nancy.ViewEngines.Razor.RazorViewEngine.RenderView.AnonymousMethod__26(System.IO.Stream流)未知Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.OutputWithDefaultTransferEncoding(Nancy.Response nancyResponsese ,System.Net.HttpListenerResponse响应)未知Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.ConvertNancyResponseToResponse(Nancy.Response nancyResponse,System.Net.HttpListenerResponse响应)未知Nancy.Hosting.Self.dll!Nancy。 Hosting.Self.NancyHost.Process(System.Net.HttpListenerContext ctx)未知的Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.GotCallback(System.IAsyncResult ar)未知的System.dll!System.Net.LazyAsyncResult Complete(System.IntPtr userToken)未知System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(对象结果,System.IntPtr userToken)未知System.dll!System.Net.ListenerAsyncResult.IOCompleted(System.Net.ListenerAsyncResult asyncResult,uint errorCode ,uint numBytes)未知的System.dll!S ystem.Net.ListenerAsyncResult.WaitCallback(uint errorCode,uint numBytes,System.Threading.NativeOverlapped * nativeOverlapped)未知mscorlib.dll!

更新:

  • 最后的堆栈跟踪似乎暗示AspNet.Web.Optimization有问题,可能与以下问题有关:

无法使System.Web.Optimization与Nancy Self Hosting一起运行

我会把所有的东西都剥离掉,以接受span标签。

<span>Hello</span>

另外,除了剃刀所需的线条外,我还会将所有内容从引导程序中删除。

如果这行得通,那么您就知道有其他原因在跳闸。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM