簡體   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