Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Shwetha Shankar 21 posts 41 karma points
    Apr 28, 2011 @ 11:52
    Shwetha Shankar
    0

    Creating new property on a document type causes 'Null Reference' exception

    Hello,

    I am fairly new to Umbraco and would like some help with a question that I am facing.

    Once I create a document type and an associated template in Umbraco, the content pages that are mapped to this doc type/template work fine. However, if I add a property on the document type and then code the required bits in the template to display the value held by the new property, I find that if I do not validate for a null entry before accessing the value of the property, pages which do not have a value for the new property throw a 'Null Reference' expection. Could you tell me why this is and if there is a more elegant way to tackle this issue.

    Thanks,
    Shwetha

  • Sebastiaan Janssen 5060 posts 15522 karma points MVP admin hq
    Apr 28, 2011 @ 12:01
    Sebastiaan Janssen
    1

    This is because the published cache for the existing documents do not yet have these properties on them. You can either check for a null reference (always a good practice) or remember to publish all of the documents of this type.

    Note: Right-clicking "Content" and choosing "Republish all" does not work, you have to actually publish all of the nodes affected, if they are under a single parent, just right-click the parent, choose "Publish" and check on "Publish this page and all of it's children".

  • Daniel Bardi 927 posts 2562 karma points
    Apr 28, 2011 @ 12:02
    Daniel Bardi
    0

    It all depends on the type of property.  What is the datatype?

  • Shwetha Shankar 21 posts 41 karma points
    Apr 28, 2011 @ 12:20
    Shwetha Shankar
    0

    Thanks for the responses. The datatype is a Textstring.

  • Sean Holmesby 61 posts 82 karma points
    May 13, 2011 @ 02:13
    Sean Holmesby
    0

    I think the issue is exactly what you say. You're accessing the value on an item that is still null. Passing a null value into GetMedia() or NiceUrl() will throw an exception.

    You should always code to check if a field value is null before using it. This IS the most elegant way to do things.

     

Please Sign in or register to post replies

Write your reply to:

Draft