Why is GetValue() extension returning Object reference not s

Posted by Community Admin on 04-Aug-2018 19:31

Why is GetValue() extension returning Object reference not set error?

All Replies

Posted by Community Admin on 08-Jul-2013 00:00

I have a very simple module that I created. I saved an item and published it and now I'm trying to retrieve the values but I'm getting an Object reference not set error when calling the GetValue() extension.

Can someone point help identify what's happening here?

var manager = DynamicModuleManager.GetManager();
var type = TypeResolutionService.ResolveType("Telerik.Sitefinity.DynamicTypes.Model.Magazine.Magazine");
var id = new Guid(id);
var item = dynamicModuleManager.GetDataItem(type, id);
 
if (item != null)
    var fullName = item.GetValue("FullName");

Posted by Community Admin on 08-Jul-2013 00:00

Hi Jeff,

I'm not sure about your module specifications regarding the fields, but try to do it like this:

var fullName = item.GetValue("FullName").ToString();

or this:
var fullName = item.GetValue<string>("FullName");

Kind regards,
Daniel

* If this post answered your questions, please mark it as answered.

Posted by Community Admin on 08-Jul-2013 00:00

I had already tried that. Still gives the object reference not set error.

Posted by Community Admin on 08-Jul-2013 00:00

Hi Jeff,

You are sure that 'item' is actually not null?
Obvious of course, but just checking.

Kind regards,
Daniel

Posted by Community Admin on 08-Jul-2013 00:00

And if you are using localized fields, you should use this code:

var fullName = item.GetValue<LString>("FullName");

Kind regards,
Daniel

Posted by Community Admin on 08-Jul-2013 00:00

Yeah, sure. I can see the properties of item, like PubliscationDate and UrlName, when I debug.

This thread is closed