Error thrown in Copystate method Version 3.5

Error thrown in Copystate method Version 3.5

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


OpticTygre posted on Friday, April 18, 2008

Created a business object and an error gets thrown when trying to set the datasource of a BindingSource to my object.  The error is thrown in the CopyState method of the CSLA where it tries to serialize the state of the object.

Error is:

Type 'Csla.PropertyInfo`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'Csla, Version=3.5.0.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30' is not marked as serializable.

All my classes are marked as serializable, so I'm not sure what's going on here.

-Jason

sergeyb replied on Friday, April 18, 2008

It is trying to serialize PropertyInfo class.  Could you include the code in your class?  That would make it easier to answer…

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: OpticTygre [mailto:cslanet@lhotka.net]
Sent: Friday, April 18, 2008 2:45 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Error thrown in Copystate method Version 3.5

 

Created a business object and an error gets thrown when trying to set the datasource of a BindingSource to my object.  The error is thrown in the CopyState method of the CSLA where it tries to serialize the state of the object.

Error is:

Type 'Csla.PropertyInfo`1[[System.Boolean, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' in Assembly 'Csla, Version=3.5.0.0, Culture=neutral, PublicKeyToken=93be5fdc093e4c30' is not marked as serializable.

All my classes are marked as serializable, so I'm not sure what's going on here.

-Jason



OpticTygre replied on Friday, April 18, 2008

That's a little difficult to do, as the inheritance chain makes the code a bit complicated.  I have some PropertyInfo objects declared as Private, and some as Public (to be able to access the friendly name).  The objects themselves are very simple, following exactly the style used in the PTTracker library.  Example:

<Serializable()> _

Public Class CommandFile

Inherits CommandBase(Of CommandFile)

#Region " Business Methods "

Private Shared IDProperty As PropertyInfo(Of Guid) = RegisterProperty(Of Guid)(GetType(CommandFile), New PropertyInfo(Of Guid)("ID"))

Public Shared ModelNumberProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(GetType(CommandFile), New PropertyInfo(Of String)("MODEL_NUMBER", "Model Number"))

Public Shared SerialNumberProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(GetType(CommandFile), New PropertyInfo(Of String)("SERIAL_NUMBER", "Serial Number"))

Public Shared TransactionsProperty As PropertyInfo(Of Transactions) = RegisterProperty(Of Transactions)(GetType(CommandFile), New PropertyInfo(Of Transactions)("TRANSACTIONS", "Transactions"))

Public ReadOnly Property ID() As Guid
   Get
      
Return GetProperty(Of Guid)(IDProperty)
   
End Get
End Property

Public Property MODEL_NUMBER() As String
   
Get
      
Return GetProperty(Of String)(ModelNumberProperty)
   
End Get
   
Set(ByVal value As String)
      SetProperty(
Of String)(ModelNumberProperty, value)
   
End Set
End Property

...Code continues....

That's basically it.  I have one more property declared in my base class, along with some MustInherit functions, but nothing out of the ordinary.

-Jason

sergeyb replied on Friday, April 18, 2008

Hmm…  I wonder if this is because you are inheriting from CommandBase?  Is this the intention?  Typically business objects should inherit from BusinessBase(Of CommandFIle).  Am I off the mark totally?

 

Sergey Barskiy

Senior Consultant

office: 678.405.0687 | mobile: 404.388.1899

cid:_2_0648EA840648E85C001BBCB886257279
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation

 

From: OpticTygre [mailto:cslanet@lhotka.net]
Sent: Friday, April 18, 2008 3:15 PM
To: Sergey Barskiy
Subject: Re: [CSLA .NET] RE: Error thrown in Copystate method Version 3.5

That's a little difficult to do, as the inheritance chain makes the code a bit complicated.  I have some PropertyInfo objects declared as Private, and some as Public (to be able to access the friendly name).  The objects themselves are very simple, following exactly the style used in the PTTracker library.  Example:

<Serializable()> _

Public Class CommandFile

Inherits CommandBase(Of CommandFile)

#Region " Business Methods "

Private Shared IDProperty As PropertyInfo(Of Guid) = RegisterProperty(Of Guid)(GetType(CommandFile), New PropertyInfo(Of Guid)("ID"))

Public Shared ModelNumberProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(GetType(CommandFile), New PropertyInfo(Of String)("MODEL_NUMBER", "Model Number"))

Public Shared SerialNumberProperty As PropertyInfo(Of String) = RegisterProperty(Of String)(GetType(CommandFile), New PropertyInfo(Of String)("SERIAL_NUMBER", "Serial Number"))

Public Shared TransactionsProperty As PropertyInfo(Of Transactions) = RegisterProperty(Of Transactions)(GetType(CommandFile), New PropertyInfo(Of Transactions)("TRANSACTIONS", "Transactions"))

Public ReadOnly Property ID() As Guid
   Get
      Return
GetProperty(Of Guid)(IDProperty)
   End Get
End
Property

Public Property MODEL_NUMBER() As String
   Get
      Return
GetProperty(Of String)(ModelNumberProperty)
   End Get
   Set
(ByVal value As String)
      SetProperty(Of String)(ModelNumberProperty, value)
   End Set
End
Property

...Code continues....

That's basically it.  I have one more property declared in my base class, along with some MustInherit functions, but nothing out of the ordinary.

-Jason



OpticTygre replied on Saturday, April 19, 2008

I don't think so.  CommandBase is defined as:

Public Class CommandBase(Of T)
   Inherits BusinessBase(Of CommandBase(Of T))

End Class

OpticTygre replied on Saturday, April 19, 2008

Ok, silly me.  I had a PropertyInfo object declared in my base class that was declared as Private instead of Private Shared.  Go fig.  It's the little things that kill you.

Thanks for the help.

-Jason

Copyright (c) Marimer LLC