Tuesday, June 9, 2009

SettingsPropertyValue.PropertyValue throws a NullReferenceException

    SettingsPropertyValue settingsPropertyValue = new SettingsPropertyValue(settingsProperty);
    settingsProperty.PropertyType = typeof(string); //Must set the type to use the PropertyValue
    settingsPropertyValue.PropertyValue = "FooBar";
    Assert.AreEqual("FooBar", settingsPropertyValue.PropertyValue);

If the SettingsProperty.PropertyType isn't set you will get a NullReferenceException when trying to access the PropertyValue.

See Also: Profile Provider Exception