Reputation: 10267
Self hosting nancy with razor returns empty body.
I'm trying to self-host nancy in a console application with razor views, however I'm getting an empty body back. It does work when running in IIS.
What I did:
I added a custom static root path provider, which seems to be configured well, as static files are served without a problem:
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();
}
}
The razor view is found an being compiled, because when I add invalid code to the view, I do get a razor compiler error
When I debug with all exceptions caught, I get an exception on serving the page:
A first chance exception of type 'Microsoft.CSharp.RuntimeBinder.RuntimeBinderException' occurred in Nancy.dll
Additional information: Cannot convert type 'Nancy.Responses.Negotiation.Negotiator' to 'Nancy.Response'
Nancy.dll!Nancy.Routing.DefaultRouteInvoker.CastResultToResponse(dynamic result) Unknown Nancy.dll!Nancy.Routing.DefaultRouteInvoker.InvokeRouteWithStrategy(dynamic result, Nancy.NancyContext context) Unknown Nancy.dll!Nancy.Routing.DefaultRouteInvoker.Invoke.AnonymousMethod__5(System.Threading.Tasks.Task completedTask) Unknown Nancy.dll!Nancy.Helpers.TaskHelpers.WhenCompleted(System.Threading.Tasks.Task task, System.Action> onComplete, System.Action> onFaulted, bool execSync) Unknown Nancy.dll!Nancy.Routing.DefaultRouteInvoker.Invoke(Nancy.Routing.Route route, System.Threading.CancellationToken cancellationToken, Nancy.DynamicDictionary parameters, Nancy.NancyContext context) Unknown Nancy.dll!Nancy.Routing.DefaultRequestDispatcher.Dispatch.AnonymousMethod__0(System.Threading.Tasks.Task completedTask) Unknown Nancy.dll!Nancy.Helpers.TaskHelpers.WhenCompleted(System.Threading.Tasks.Task task, System.Action> onComplete, System.Action> onFaulted, bool execSync) Unknown Nancy.dll!Nancy.Routing.DefaultRequestDispatcher.Dispatch(Nancy.NancyContext context, System.Threading.CancellationToken cancellationToken) Unknown Nancy.dll!Nancy.NancyEngine.InvokeRequestLifeCycle.AnonymousMethod__9(System.Threading.Tasks.Task t) Unknown Nancy.dll!Nancy.Helpers.TaskHelpers.WhenCompleted(System.Threading.Tasks.Task task, System.Action> onComplete, System.Action> onFaulted, bool execSync) Unknown Nancy.dll!Nancy.NancyEngine.InvokeRequestLifeCycle(Nancy.NancyContext context, System.Threading.CancellationToken cancellationToken, Nancy.Bootstrapper.IPipelines pipelines) Unknown Nancy.dll!Nancy.NancyEngine.HandleRequest(Nancy.Request request, System.Func preRequest, System.Threading.CancellationToken cancellationToken) Unknown Nancy.dll!Nancy.NancyEngineExtensions.HandleRequest(Nancy.INancyEngine nancyEngine, Nancy.Request request, System.Func preRequest) Unknown Nancy.dll!Nancy.NancyEngineExtensions.HandleRequest(Nancy.INancyEngine nancyEngine, Nancy.Request request) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.Process(System.Net.HttpListenerContext ctx) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.GotCallback(System.IAsyncResult ar) Unknown System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) Unknown System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, System.IntPtr userToken) Unknown System.dll!System.Net.ListenerAsyncResult.IOCompleted(System.Net.ListenerAsyncResult asyncResult, uint errorCode, uint numBytes) Unknown System.dll!System.Net.ListenerAsyncResult.WaitCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) Unknown mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) Unknown
Then followed by a ArgumentNullException:
System.ArgumentNullException occurred Message: A first chance exception of type 'System.ArgumentNullException' occurred in System.Web.dll Additional information: Value cannot be null.
System.Web.dll!System.Web.HttpContextWrapper.HttpContextWrapper(System.Web.HttpContext httpContext) Unknown System.Web.Optimization.dll!System.Web.Optimization.Styles.Context.get() Unknown System.Web.Optimization.dll!System.Web.Optimization.Styles.RenderFormat(string tagFormat, string[] paths) Unknown Temp_bfd13a3e77214eca9b1ce8f1a37d244d.dll!RazorOutput.RazorView.Execute() Unknown Nancy.ViewEngines.Razor.dll!Nancy.ViewEngines.Razor.NancyRazorViewBase.ExecuteView(string body, System.Collections.Generic.IDictionary sectionContents) Unknown [Lightweight Function]
Nancy.ViewEngines.Razor.dll!Nancy.ViewEngines.Razor.RazorViewEngine.RenderView.AnonymousMethod__26(System.IO.Stream stream) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.OutputWithDefaultTransferEncoding(Nancy.Response nancyResponse, System.Net.HttpListenerResponse response) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.ConvertNancyResponseToResponse(Nancy.Response nancyResponse, System.Net.HttpListenerResponse response) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.Process(System.Net.HttpListenerContext ctx) Unknown Nancy.Hosting.Self.dll!Nancy.Hosting.Self.NancyHost.GotCallback(System.IAsyncResult ar) Unknown System.dll!System.Net.LazyAsyncResult.Complete(System.IntPtr userToken) Unknown System.dll!System.Net.LazyAsyncResult.ProtectedInvokeCallback(object result, System.IntPtr userToken) Unknown System.dll!System.Net.ListenerAsyncResult.IOCompleted(System.Net.ListenerAsyncResult asyncResult, uint errorCode, uint numBytes) Unknown System.dll!System.Net.ListenerAsyncResult.WaitCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* nativeOverlapped) Unknown mscorlib.dll!System.Threading._IOCompletionCallback.PerformIOCompletionCallback(uint errorCode, uint numBytes, System.Threading.NativeOverlapped* pOVERLAP) Unknown
UPDATE:
Can't get System.Web.Optimization to run with Nancy Self Hosting
Upvotes: 0
Views: 1335
Reputation: 23526
I would strip everything out of the view accept for a span tag.
<span>Hello</span>
Also I would strip everything out of the bootstrapper except the lines needed for razor.
If this works then you know something else is tripping it up.
Upvotes: 1