Server Error in '/' Application.

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 20: 	if (!string.IsNullOrEmpty(departmentID)) {
Line 21: 		var department = Services.Items.GetItemById<Nh1816.ItemTypes.TPOffice>(departmentID);
Line 22: 		office = department.ToCodeFirstItem<Nh1816.ItemTypes.TPOffice>();
Line 23: 		officeDepartments.Add(mainOffice);
Line 24: 		officeDepartments = officeDepartments.Where(d => d.Id != office.Id).ToList();

Source File: D:\Dynamicweb.NET\Nh1816Productie\files\Templates\Designs\NH1816_generated\_parsed\TPOffice.parsed.cshtml    Line: 22

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   CompiledRazorTemplates.Dynamic.RazorEngine_0aed1e63de0e47dcaddd388ba2de24ed.Execute() in D:\Dynamicweb.NET\Nh1816Productie\files\Templates\Designs\NH1816_generated\_parsed\TPOffice.parsed.cshtml:22
   RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader) +211
   RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag) +88
   RazorEngine.Templating.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer) +93
   RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter) +68
   Dynamicweb.Rendering.Template.RenderRazorTemplate() +3449
   Dynamicweb.Rendering.Template.Output() +466
   Dynamicweb.Frontend.PageView.Output() +1614
   Dynamicweb.Frontend.DynamicwebHttpHandler.ProcessRequest(HttpContext context) +221
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +866
   System.Web.HttpApplication.ExecuteStepImpl(IExecutionStep step) +213
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +91


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.7.4087.0