Partial views render in debug mode but not release mode.
stack trace
[ArgumentNullException: Value cannot be null.
Parameter name: key]
System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory) +5895838
Nancy.ViewEngines.DefaultViewCache.GetOrAdd(ViewLocationResult viewLocationResult, Func`2 valueFactory) +329
Nancy.ViewEngines.Razor.RazorViewEngine.GetOrCompileView(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Type passedModelType) +186
System.Dynamic.UpdateDelegates.UpdateAndExecute5(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) +401
CallSite.Target(Closure , CallSite , RazorViewEngine , ViewLocationResult , IRenderContext , Assembly , Object ) +575
Nancy.ViewEngines.Razor.RazorViewEngine.GetViewInstance(ViewLocationResult viewLocationResult, IRenderContext renderContext, Assembly referencingAssembly, Object model) +1128
System.Dynamic.UpdateDelegates.UpdateAndExecute5(CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4) +401
CallSite.Target(Closure , CallSite , RazorViewEngine , ViewLocationResult , IRenderContext , Assembly , Object ) +495
Nancy.ViewEngines.Razor.<>c__DisplayClass1f.<RenderView>b__1e(Stream stream) +470
Nancy.ViewEngines.Razor.HtmlHelpers`1.Partial(String viewName, Object modelForPartial) +1872
RazorOutput.RazorView.<Execute>b__3() +632
Nancy.ViewEngines.Razor.NancyRazorViewBase`1.ExecuteView(String body, IDictionary`2 sectionContents) +374
Nancy.ViewEngines.Razor.<>c__DisplayClass1f.<RenderView>b__1e(Stream stream) +775
Nancy.Hosting.Aspnet.NancyHandler.ProcessRequest(HttpContextBase context) +81
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +913
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +165
master.cshtml (relevant section only)
@if (IsSectionDefined("sidebar")) {
<div id="two-col">
@RenderBody()
</div>
<div id="sidebar">
@RenderSection("sidebar")
</div>
} else {
<div id="one-col">
@RenderBody()
</div>
}
index.cshtml
@inherits Nancy.ViewEngines.Razor.NancyRazorViewBase<dynamic>
@{ Layout = "master.cshtml"; }
// html for body, doesn't use model
@section sidebar {
@Html.Partial("/sidebars/sidebar.cshtml", Model)
}
sidebar.cshtml (sample section)
<ul>
@foreach (var item in Model.Items)
{
<li>@Html.Raw(@item.DisplayText)</li>
}
</ul>
In our case the problem was that the Views we were referring to were missing the setting:
Build Action: Content
Meaning in debug mode the files were being read from the file system, but were not being copied to the release bin folder when running in release mode.
I had this problem recently, but linked to my master layout pages. Looking at your index page it could one of two things, like me, the path to your master page or the path to your partial. If you remove the leading slash on your partial url or if your master page is in a shared folder, add the full path to its url (without leading slashes or ~/).
This is where I found the solution. https://groups.google.com/forum/#!topic/nancy-web-framework/zRLth_hl2r8
HTH
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With