Custom Principal Not Serializable - SilverlightCustom Principal Not Serializable - Silverlight
Old forum URL: forums.lhotka.net/forums/t/8294.aspx
GregDobbs posted on Wednesday, January 06, 2010
Hello all.
I've created custom Identity and Principal objects - see attached. Each class is separated into a server-side and client (Silverlight) partial class. Logging in works fine.
However, when I go to fetch a busines object I get the following error:
System.InvalidOperationException was unhandled by user code
Message="Object not serializable (dazCore.Library.Security.dazPrincipal)"
StackTrace:
at Csla.Serialization.Mobile.MobileFormatter.SerializeObject(Object obj)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(XmlWriter writer, Object graph)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(Stream serializationStream, Object graph)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(Object obj)
at Csla.DataPortalClient.WcfProxy`1.GetBaseCriteriaRequest()
at Csla.DataPortalClient.WcfProxy`1.BeginFetch(Object criteria, Object userState)
at Csla.DataPortal`1.BeginFetch(Object criteria, Object userState)
at dazCore.Library.NewMember.GetNewMemberByeMail(String eMail, EventHandler`1 callback)
at dazPublicPortal.pageWelcome.TestFetch()
at dazPublicPortal.pageWelcome.btnRegister_Click(Object Sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
Can anyone see something in my code that's causing the principal or identity objects to be unserializable?
Thanks!sergeyb replied on Wednesday, January 06, 2010
Are they decorated with Serializable attribute? What base classes do they inherit from?
Sergey Barskiy
Principal Consultant
office: 678.405.0687 | mobile: 404.388.1899
Microsoft Worldwide Partner of the Year | Custom Development Solutions, Technical Innovation
-----Original Message-----
From: GregDobbs [mailto:cslanet@lhotka.net]
Sent: Wednesday, January 06, 2010 7:13 PM
To: Sergey Barskiy
Subject: [CSLA .NET] Custom Principal Not Serializable - Silverlight
Hello all.
I've created custom Identity and Principal objects - see attached. Each class is separated into a server-side and client (Silverlight) partial class. Logging in works fine.
However, when I go to fetch a busines object I get the following error:
System.InvalidOperationException was unhandled by user code
Message="Object not serializable (dazCore.Library.Security.dazPrincipal)"
StackTrace:
at Csla.Serialization.Mobile.MobileFormatter.SerializeObject(Object obj)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(XmlWriter writer, Object graph)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(Stream serializationStream, Object graph)
at Csla.Serialization.Mobile.MobileFormatter.Serialize(Object obj)
at Csla.DataPortalClient.WcfProxy`1.GetBaseCriteriaRequest()
at Csla.DataPortalClient.WcfProxy`1.BeginFetch(Object criteria, Object userState)
at Csla.DataPortal`1.BeginFetch(Object criteria, Object userState)
at dazCore.Library.NewMember.GetNewMemberByeMail(String eMail, EventHandler`1 callback)
at dazPublicPortal.pageWelcome.TestFetch()
at dazPublicPortal.pageWelcome.btnRegister_Click(Object Sender, RoutedEventArgs e)
at System.Windows.Controls.Primitives.ButtonBase.OnClick()
at System.Windows.Controls.Button.OnClick()
at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e)
at System.Windows.Controls.Control.OnMouseLeftButtonUp(Control ctrl, EventArgs e)
at MS.Internal.JoltHelper.FireEvent(IntPtr unmanagedObj, IntPtr unmanagedObjArgs, Int32 argsTypeIndex, String eventName)
InnerException:
Can anyone see something in my code that's causing the principal or identity objects to be unserializable?
Thanks!
GregDobbs replied on Wednesday, January 06, 2010
Hello, Sergey.
Your response pointed me in the right direction. My classes inherited appropriately from BusinessPrincipalBase and CSLAIdentity.
It was the Serializable attribute that was the issue. I had the Serializable attribute applied on the SERVER partial class, not on the SHARED partial class available to Silverlight.
Thus, the Silverlight client had no idea that the class was Serializable.
Once I removed the Serializable attribute from the Server-side class and put it on the Shared class instead the issue was resolved.
Thanks for steering me in the right direction!elizas replied on Tuesday, February 02, 2010
If we want to serialize and deSerialize an object in silverlight We have to use DataContractSerializer as Silverlight doesn't support BinaryFormatter.
DataContractSerializer under the type System.Runtime.Serialization Serializes and deserializes an instance of a type into an XML stream using dataContract.
Create a Silverlight-enabled wcf service and define the data contract and Datamember attributes withing the .svc.
Imports System.ServiceModel
End ClassCopyright (c) Marimer LLC