This project is read-only.


Non-nullable types get NullReferenceException when not set


If i use the following property in a PageTypePropertyGroup i will receive a NullReferenceException if the value is not set inside EPiServer
[PageTypeProperty(EditCaption="Sample date", SortOrder = 1)]
public virtual DateTime DateTime { get; set; }
I have checked out the code (GetPropertyGroupPropertyValue) and it seems like it is because the value is unconditionally cast to TProperty rather than to null check the underlying value and then return default(TProperty)
I guess the same applies for properties that is defined directly on the TypedPageType, but I have not confirmed it.
Closed Jan 27, 2012 at 11:24 PM by joelabrahamsson
You should almost always use the nullable equivalent of value types as that's what maps to the actual value of a property in EPiServer. One could definitely argue that the exception message should be something more informative though, but this in it self isn't a bug.If you want to, you could always implement the getter yourself and do a null check, like get{ return (DateTime) this.GetPropertyValue<object>() ?? DateTime.MinValue; }