And the SendInternalEmail method roughly like this:
private void SendInternalEmail(MyModel model)
{
//NOTE: the GetPropertyValue throws a NullReferenceException when this method is run async!
//-even though the node is correctly found and the prop can be seen on it with a value
var node = Umbraco.TypedContent(model.NodeId);
string emailAddress = node.GetPropertyValue<string>("internalEmailAddress");
The umbraco logs show this (confidential code replaced with mycode):
2016-03-28 10:29:19,663 [P10052/D15/T471] ERROR <mycode> - Object reference not set to an instance of an object.
System.NullReferenceException: Object reference not set to an instance of an object.
at Umbraco.Web.Templates.TemplateUtilities.ParseInternalLinks(String text, Boolean preview)
at Umbraco.Web.PropertyEditors.ValueConverters.TextStringValueConverter.ConvertDataToSource(PublishedPropertyType propertyType, Object source, Boolean preview)
at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__0()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Umbraco.Web.PublishedCache.XmlPublishedCache.XmlPublishedProperty.<.ctor>b__1()
at System.Lazy`1.CreateValue()
at System.Lazy`1.LazyInitValue()
at Umbraco.Web.PublishedPropertyExtension.GetValue[T](IPublishedProperty property, Boolean withDefaultValue, T defaultValue)
at Umbraco.Web.PublishedContentExtensions.GetPropertyValue[T](IPublishedContent content, String alias)
at <mycode>.SendInternalEmail(MyModel model) in C:\Development\<mycode>:line 71
Any one seen this? Am I missing something? Im using umbraco v7.4.
I am not sure if it is related but since moving to Umbraco 7.4 I have experience a few similar problems. My problems have mainly been running umbraco saves within the background tasks. The gets I haven't really noticed any problems but I haven't looked at the logs in a while.
Basically the problems I've been having is the context is missing and when I attempt to update / save something into umbraco within a background task it fails.
I googled around and found an hack to fake the context.
//fake the context to get around an error
//exception details: Value cannot be null.Parameter name: httpContext
HttpContext.Current = new HttpContext(new HttpRequest(null, "https://www.google.com", null), new HttpResponse(null));
I am not sure if your issues are caused by the same thing but I have a feeling they might be. Try adding this block of code before dealing with the Umbraco gets and sets. See if it helps.
Hey, I know this is an old post but I ran into a similar issue and was able to resolve it. I passed reference to the the current Umbraco context to the async function and then in that function I got the property like so:
Task.Run with GetPropertyValue gives NullRefException
Hi lovely umbraco community :) I wonder if anyone has seen this / if its by design:
I have a NullReferenceException being generated when I try to use GetPropertyValue within a method called from Task.Run, within a surface controller.
The Task.Run part looks like this:
And the SendInternalEmail method roughly like this:
The umbraco logs show this (confidential code replaced with
mycode
):Any one seen this? Am I missing something? Im using umbraco v7.4.
tia Ian
Hi,
I am not sure if it is related but since moving to Umbraco 7.4 I have experience a few similar problems. My problems have mainly been running umbraco saves within the background tasks. The gets I haven't really noticed any problems but I haven't looked at the logs in a while.
Basically the problems I've been having is the context is missing and when I attempt to update / save something into umbraco within a background task it fails.
I googled around and found an hack to fake the context.
I am not sure if your issues are caused by the same thing but I have a feeling they might be. Try adding this block of code before dealing with the Umbraco gets and sets. See if it helps.
Kind Regards
David
Have you managed to fix this problem?
I'm currently experiencing the exact same problem. Running a task with a GetPropertyValue call in it returns a NullReferenceException
I've tried adding the fake HttpContext on a few places, but no luck so far.
Kind regards,
Mark
Hi Mark
no I didnt fix it, I just worked around it by getting all the properties I needed before the Task.Run call and just passing them in.
Ian
Hey, I know this is an old post but I ran into a similar issue and was able to resolve it. I passed reference to the the current Umbraco context to the async function and then in that function I got the property like so:
Hope this helps somebody.
Legend! Works fine any idea if the value is an Id or Udi, how I can access that entity as well?
is working on a reply...