Paul's profilePaul Galvin's SharePoint...BlogListsSkyDrive Tools Help

Blog


    February 26

    Simple Explanation: "Value does not fall within the expected range."

    UPDATE: An anonymous poster left a great comment about internal names.  Be sure to read it.

    When working with event receivers and other code that references SharePoint list items via the object model, I often make mistakes that generate this error at runtime:

    Error loading and running event receiver Conchango.xyzzyEventReceiver in xyzzy, Version=1.0.0.0, Culture=neutral, PublicKeyToken=0dc50a750396c3ac. Additional information is below.  : Value does not fall within the expected range.    

    I think this is a fairly generic error that is potentially caused many different ways.  However, one simple explanation is that I'm referencing a field incorrectly.  If the name of the field is "Due Date", I must reference it like this in an event receiver:

    properties.ListItem["Due Date"]

    When I misspell or use the wrong case when referencing the field, SharePoint generates the above mentioned runtime error.  For example, this is wrong:

    properties.ListItem["due Date"]

    </end>

    Subscribe to my blog.

    Technorati Tags:

    Comments (1)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    I agree with paul but i also want to add something for this exception.
    Sometime the Field Name is different than the Field Internal Name in the list so trying to access the field using Field Name in the object model gives us the above exception. To resolve this problem always try to access the fields using their Internal Names.
    How can you find the internal Names of the Fields?
    1) Go To Sharepoint List.  Go to New | New Item.
    2) New Item form will be displayed. Right click on the form and click on View Source. Search for the Field Internal Name in the opened HTML code. You will find the Field Internal Name along with Field Name.
    Mar. 25

    Trackbacks (1)

    The trackback URL for this entry is:
    http://paulgalvin.spaces.live.com/blog/cns!1CC1EDB3DAA9B8AA!779.trak
    Weblogs that reference this entry