Property not marked as serializable error since upgrading to 3.5.1

Property not marked as serializable error since upgrading to 3.5.1

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


Marjon1 posted on Tuesday, January 05, 2010

I've moved our CSLA version from 3.5.0 to 3.5.1 and am now getting an error that I cannot determine the cause of, no matter how much digging into the framework I do.

The error received is:
Type 'Csla.PropertyInfo`1[[Sybiz.Visipay.Platform.Business.Payroll.PayDates,
Sybiz.Visipay.Platform, Version=1.0.3658.24857, Culture=neutral, PublicKeyToken=null]]'
in Assembly 'Csla, Version=3.6.0.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30' is not marked as serializable. (ignore the fact that it says 3.6, same error on 3.5.1)

The parent class has the property declared as follows:

Private _payDate As PayDates = Nothing
Private _payDateProperty As PropertyInfo(Of PayDates) = RegisterProperty(Of PayDates)(New PropertyInfo(Of PayDates)("PayDateObj"))
Public Property PayDateObj() As PayDates
Get
If (_payDate Is Nothing) Then
_payDate = PayDates.GetDates()
End If
Return GetProperty(Of PayDates)(_payDateProperty, _payDate)
End Get
Set(ByVal value As PayDates)
SetProperty(Of PayDates)(_payDateProperty, _payDate, value)
End Set
End Property


The PayDates class has had all actual code removed and all properities just returning hard-coded values (for now) and is declared as such:

[Serializable()] _
Public Class PayDates
Inherits VisipayBusinessBase(Of PayDates)

'Code missing to cut down on post size, doesn't do very much at all

End Class


The error actually occurs when the object is attached to a binding source as part of the CopyState method when it attempts to serialize the propertyInfo buffer.

The really odd thing is that if I change the CSLA version back to 3.5.0 (previous version we used) then it all works fine and I cannot see anything in the changelog that would suggest what could be causing this problem to appear.
I've had to adjust the code a little bit for it to be presentable within the editor, but it does compile and run without modification, so any silly things like [ can be ignored.

Thanks for any responses in advance and apologies about the code formatting, can never get it to look good.

John

RockfordLhotka replied on Tuesday, January 05, 2010

PropertyInfo(Of T) fields must be static - you are declaring it as an instance field. I don't know why it ever worked, this has never been legal.

Marjon1 replied on Wednesday, January 06, 2010

I can't believe that I couldn't see that!

Thanks Rocky, I too am confused how this ever worked.
Looks like it's time for another code review to find any other bad PropertyInfo(Of T) declarations.

Copyright (c) Marimer LLC