2
Vote

System.NullReferenceException at TaskData.GetProperty

description

Hi,
I am using .ascx user controls without Association and Initiation forms.
In this scenario the ascx LoadData method throws a System.NullReferenceException when trying to access any taskdata value.
I have edited TaskData.GetProperty to avoid the System.NullReferenceException like this:
 
BEFORE:
object GetProperty(object key)
    {
        DataItem value = null;
        if (_contentTypePropertyKeys.ContainsKey(key))
        {
            SPField field = _contentTypePropertyKeys[key];
            value = _taskData[field.Id];
        }
        else if (_taskData.ContainsKey(key))
        {
            value = _taskData[key];
        }
        return value.Value;  // value can be null in some possible scenario so System.NullReferenceException  
    }
AFTER:
object GetProperty(object key)
    {
        DataItem value = null;
        if (_contentTypePropertyKeys.ContainsKey(key))
        {
            SPField field = _contentTypePropertyKeys[key];
            value = _taskData[field.Id];
        }
        else if (_taskData.ContainsKey(key))
        {
            value = _taskData[key];
        }
        return (value != null) ? value.Value : null;   // Check for null before use!
    }

comments