我想补充一下答案,因为我花了大约一天的时间试图弄清楚这一点:。
Nancy.RequestExecutionException: Oh noes! ---> System.NullReferenceException: Object reference not set to an instance of an object.
at Nancy.ViewEngines.DefaultViewCache.GetOrAdd[TCompiledView](ViewLocationResult viewLocationResult, Func`2 valueFactory)
at Nancy.ViewEngines.Razor.RazorViewEngine.GetOrCompileView(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Type passedModelType)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at CallSite.Target(Closure , CallSite , RazorViewEngine , ViewLocationResult , IRenderContext , Assembly , Object )
at Nancy.ViewEngines.Razor.RazorViewEngine.GetViewInstance(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Object model)
at System.Dynamic.UpdateDelegates.UpdateAndExecute5[T0,T1,T2,T3,T4,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
at Nancy.ViewEngines.Razor.RazorViewEngine.<>c__DisplayClass27.b__26(Stream stream)
at Nancy.Responses.MaterialisingResponse.PreExecute(NancyContext context)
与 Richard Banks 的回答类似 - Nancy 不会解析 Views/_ViewStart.cshtml 文件中的默认布局路径(即:~/Views/Shared/_Layout.cshtml)。~/ 在 Nancy 的视图解析器中没有被解释。
您可以删除 ~/ 部分,或注释掉默认布局并手动指定每个视图的布局。我做后者的原因是,即使您已取消视图中的布局,Nancy 仍会执行 _Layout.cshtml。