Object reference not set to an instance of an object
Hello Umbracians,
I've got a development site up on Vidahost and it was working fine over the weekend, no one has accessed the backend of Umbraco so not sure what has gone but i now get this error.
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:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
umbraco.library.GetXmlNodeByXPath(String xpathQuery) +83
[TargetInvocationException: Exception has been thrown by the target of an invocation.]
System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor) +0
System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments) +76
System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture) +193
UmbracoExamine.DataServices.UmbracoContentService.GetPublishedContentByXPath(String xpath) +117
UmbracoExamine.BaseUmbracoIndexer.AddNodesToIndex(String xPath, String type) +31
UmbracoExamine.BaseUmbracoIndexer.PerformIndexAll(String type) +1008
UmbracoExamine.UmbracoContentIndexer.PerformIndexAll(String type) +618
UmbracoExamine.BaseUmbracoIndexer.PerformIndexRebuild() +98
Examine.ExamineManager._RebuildIndex() +141
Umbraco.Web.WebBootManager.<InitializeResolvers>b__c() +277
Umbraco.Core.Sync.DatabaseServerMessenger.Initialize() +370
Umbraco.Core.Sync.DatabaseServerMessenger.Boot() +194
Umbraco.Core.CoreBootManager.<Complete>b__8(IApplicationEventHandler x) +220
Umbraco.Core.EnumerableExtensions.ForEach(IEnumerable`1 items, Action`1 action) +148
Umbraco.Core.CoreBootManager.Complete(Action`1 afterComplete) +320
Umbraco.Web.WebBootManager.Complete(Action`1 afterComplete) +95
Umbraco.Core.UmbracoApplicationBase.StartApplication(Object sender, EventArgs e) +355
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpApplicationFactory.EnsureAppStartCalledForIntegratedMode(HttpContext context, HttpApplication app) +12964021
System.Web.HttpApplication.RegisterEventSubscriptionsWithIIS(IntPtr appContext, HttpContext context, MethodInfo[] handlers) +175
System.Web.HttpApplication.InitSpecial(HttpApplicationState state, MethodInfo[] handlers, IntPtr appContext, HttpContext context) +304
System.Web.HttpApplicationFactory.GetSpecialApplicationInstance(IntPtr appContext, HttpContext context) +404
System.Web.Hosting.PipelineRuntime.InitializeApplication(IntPtr appContext) +475
[HttpException (0x80004005): Exception has been thrown by the target of an invocation.]
System.Web.HttpRuntime.FirstRequestInit(HttpContext context) +12981028
System.Web.HttpRuntime.EnsureFirstRequestInit(HttpContext context) +159
System.Web.HttpRuntime.ProcessRequestNotificationPrivate(IIS7WorkerRequest wr, HttpContext context) +12820621
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34274
I believe this may be something to do with one of the surface controllers i have for the custom built contact form.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Xml.XPath;
using Umbraco.Core.Services;
using Umbraco.Web.Mvc;
/// <summary>
/// Summary description for ContactSurfaceController
/// </summary>
namespace LiquidThinker2015
{
public class ContactSurfaceController : SurfaceController
{
public object XPathModeIterator { get; private set; }
public ActionResult ShowForm()
{
ContactModel myModel = new ContactModel();
List<SelectListItem> ListOfServices = new List<SelectListItem>();
XPathNodeIterator iterator = umbraco.library.GetPreValues(1435);
iterator.MoveNext();
XPathNodeIterator preValues = iterator.Current.SelectChildren("preValue", "");
while (preValues.MoveNext())
{
string preValue = preValues.Current.GetAttribute("id", "");
ListOfServices.Add(new SelectListItem
{
Text = preValues.Current.Value,
Value = preValues.Current.GetAttribute("id","")
});
myModel.ListOfServices = ListOfServices;
}
return PartialView("ContactForm", myModel);
}
public ActionResult HandleFormPost(ContactModel model)
{
var newComment = Services.ContentService.CreateContent(model.Name + " - " + DateTime.Now.ToString("dd/MM/yyyy HH:mm"), CurrentPage.Id, "ContactFormula");
//DataTypeService myService = new DataTypeService();
//var SelectedService = myService.GetAllDataTypeDefinitions().First(x => x.Id == 1435);
//int SelectedServicePreValueId = myService.GetPreValuesCollectionByDataTypeId(SelectedService.Id).PreValuesAsDictionary.Where(x => x.Value.Value == model.SelectedService).Select(x => x.Value.Id).First();
newComment.SetValue("contactName", model.Name);
newComment.SetValue("companyName", model.Company);
newComment.SetValue("emailFrom", model.Email);
newComment.SetValue("telephoneNumber", model.Telephone);
newComment.SetValue("dropdownServices", model.SelectedService);
newComment.SetValue("contactMessage", model.Message);
Services.ContentService.SaveAndPublishWithStatus(newComment);
return RedirectToUmbracoPage(1454);
//return RedirectToCurrentUmbracoPage();
}
}
}
Any ideas as to what's gone wrong here? I guess there is a value not being set somewhere?
I wonder if there was an actual problem with the connection string, or if just you editing the Web.config forced the site to restart and that is what actually fixed your issue. When nothing has changed and I start getting weirdness like this I'll touch the Web.config first and see if that fixes it. I generally add a comment at the bottom of the file and increment it. Something like this:
<!-- Touches: abcd -->
I had a site just this morning that was complaining about a missing file (it wasn't missing) and I just added the next letter to my touches comment and it was good.
Object reference not set to an instance of an object
Hello Umbracians,
I've got a development site up on Vidahost and it was working fine over the weekend, no one has accessed the backend of Umbraco so not sure what has gone but i now get this error.
I believe this may be something to do with one of the surface controllers i have for the custom built contact form.
Any ideas as to what's gone wrong here? I guess there is a value not being set somewhere?
For anyone with the same error as me the connection string needs to have \dbname and append flush interval=1 as well.
I wonder if there was an actual problem with the connection string, or if just you editing the Web.config forced the site to restart and that is what actually fixed your issue. When nothing has changed and I start getting weirdness like this I'll touch the Web.config first and see if that fixes it. I generally add a comment at the bottom of the file and increment it. Something like this:
I had a site just this morning that was complaining about a missing file (it wasn't missing) and I just added the next letter to my touches comment and it was good.
Yeah, best place to start is the web.config then take it from there. Glad i got my issue sorted.
Thanks for taking the time in contributing to my post.
is working on a reply...