I added a business object property that is of type XElement: //HouseholdDemographicsXML Property The following loads the property:
private static PropertyInfo<XElement> HouseholdDemographicsXMLProperty =
"Household Demographics XML"));
public XElement HouseholdDemographicsXML
{
get { return GetProperty(HouseholdDemographicsXMLProperty); }
set { SetProperty(HouseholdDemographicsXMLProperty, value); }
}
LoadProperty(HouseholdDemographicsXMLProperty, XElement.Parse(data.Demographics));
where data.Demographics is a string representing an XML fragment. The problem is that when I try to instantiate the object I get the message: Type System.Xml.Linq.XElement in Assembly System.Xml.Linq is not marked as serializable Does this mean I can't use XElement as a business object property type? Is there a workaround? Could I create a new class inheriting from XElement and somehow mark it as Serializable?
If a type is not Serializable there's nothing you can do - you can't make someone else's type Serializable.
What you can do is maintain the value itself as a string. Remember that CSLA doesn't serialize properties - it serializes fields. You can have an XElement property, as long as the backing value is of a serializable type (like string).
Thanks for posting your issue Russelle!
And thanks for the tip Rocky! This solved my issue.
Here's an example of how I applied your suggestion in my business object...
Public Shared ReadOnly MyXElementDataProperty As PropertyInfo(Of String) = RegisterProperty(New PropertyInfo(Of String)("MyXElementData", "My XElement Data", New XElement("Data")))
Protected Property MyXElementData() As XElement
Get
Return XElement.Parse(GetProperty(MyXElementDataProperty))
End Get
Set(ByVal value As XElement)
SetProperty(MyXElementDataProperty, value)
End Set
End Property
Regards,
Carlo
Copyright (c) Marimer LLC