+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / Why is GetValue() extension returning Object reference not set error?

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

6 posts, 0 answered
  1. Jeff
    Jeff avatar
    118 posts
    Registered:
    08 Jul 2011
    08 Jul 2013
    Link to this post
    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");
    }
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    08 Jul 2013
    Link to this post
    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.
  3. Jeff
    Jeff avatar
    118 posts
    Registered:
    08 Jul 2011
    08 Jul 2013 in reply to Daniel Plomp
    Link to this post
    I had already tried that. Still gives the object reference not set error.
  4. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    08 Jul 2013 in reply to Jeff
    Link to this post
    Hi Jeff,

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

    Kind regards,
    Daniel
  5. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    08 Jul 2013 in reply to Daniel Plomp
    Link to this post
    And if you are using localized fields, you should use this code:

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

    Kind regards,
    Daniel
  6. Jeff
    Jeff avatar
    118 posts
    Registered:
    08 Jul 2011
    08 Jul 2013 in reply to Daniel Plomp
    Link to this post
    Yeah, sure. I can see the properties of item, like PubliscationDate and UrlName, when I debug.
6 posts, 0 answered