StrataFrame Forum

Unable to cast object of type 'System.DBNull' to type 'System.Byte[]

http://forum.strataframe.net/Topic12053.aspx

By MarcoR - 10/17/2007

Hi, I am reading an image field from the database into a property of type[]. When the field is null, I get an Unable to cast object of type 'System.DBNull' to type 'System.Byte[]  error. I have changed the StrataFrame generated code for the BO to fix it, but is there some setting that I need to make when generating the BO so this is automatically handled correctly in the generated BO? BigGrin
By Greg McGuffey - 10/18/2007

I'm not sure if one of the "return alternate on null" settings would work in this situation, but you could just put your custom code in the custom code area of the BO Mapper (the big text box at the bottom of the field customization form). That way every time your BO is rebuild within the mapper, this code gets used.
By MarcoR - 10/18/2007

Thanks! I used new byte[] {} in the alternate and that worked.
By Greg McGuffey - 10/18/2007

Cool!
By Peter Jones - 10/18/2007

Hi Guys,

FYI we use "return alternate on null > Nothing" for TimeStamp columns and that works fine to.

I say this because I'm pretty sure the we get a "System.DBNull' to type System.Byte[]" error if we don't get the Timestamp setting correct in the BO Mapper.

Cheers, Peter