Invalid cast from System.String to Csla.SmartDate.

Invalid cast from System.String to Csla.SmartDate.

Old forum URL: forums.lhotka.net/forums/t/9413.aspx


Stuart posted on Friday, August 20, 2010

I'm receiving this exception in the Utilities\CoerceValue() function when trying to save a change made in a DateTimePicker (WinForms) which is bound to a SmartDate field. The binding works both ways and the  string value in this case is 02/08/2001. Here's my property definition:

public static PropertyInfo<SmartDate> OrderDateProperty = RegisterProperty<SmartDate>(p => p.OrderDate);
        public string OrderDate
        {
            get { return GetProperty(OrderDateProperty); }
            set { SetProperty(OrderDateProperty, value); }
        }

Can anyone help?

JonnyBee replied on Friday, August 20, 2010

When the backing field and property is different types, here SmartDate and string, you must use SetPropertyConvert/GetPropertyConvert.

 

Copyright (c) Marimer LLC