I'm a total F# n00b, so I hope i give you enough information. I created a class called record. I create several instances of this class with data from our database. I then add each record to a list of records. i want to make an xml document with those records.
//this is the record data type i created. I also created a sender and recipient data
//type but those are probably not neccessary to understand the issue
type record(id:int, sender:sender, ?recipients: recipient list ) =
let mutable id: int = id
let mutable typ = "Message"
let mutable creation = creation()
let mutable sender = sender
let mutable recipients = recipients
[<XmlIgnore()>]
[<XmlArrayAttribute("recipients")>]
[<XmlArrayItem(typeof<recipient>, ElementName = "recipient")>]
member this.Recipients with get() = recipients and set v = recipients <- v
public new() =
record(12180, sender(12180,"Joe","Plumber","[email protected]"), list.Empty)
[<XmlElement("id")>]
member this.Id with get() = id and set v = id <- v
[<XmlElement("creation")>]
member this.Creation with get() = creation and set v = creation <- v
[<XmlElement("sender")>]
member this.Sender with get() = sender and set v = sender <- v
//i later call this:
let xmlSerializer = XmlSerializer(typeof<record list>)
I then get this error message at runtime:
There was an error reflecting type 'Microsoft.FSharp.Collections.FSharpList`1[XXXX.Compliance.YYYYY.record]'. //x's and y's used to protect the innocent.
As with the CreatePo method, you must first construct an XmlSerializer, passing the type of class to be deserialized to the constructor. Also, a FileStream is required to read the XML document. To deserialize the objects, call the Deserialize method with the FileStream as an argument.
XML serialization is the process of converting XML data from its representation in the XQuery and XPath data model, which is the hierarchical format it has in a Db2® database, to the serialized string format that it has in an application.
Xml. Serialization namespace contains several Attribute classes that can be applied to members of a class. For example, if a class contains a member that will be serialized as an XML element, you can apply the XmlElementAttribute attribute to the member.
XmlSerializer enables you to control how objects are encoded into XML. The XmlSerializer enables you to control how objects are encoded into XML, it has a number of constructors.
Caveat: I am not sure.
I think that some F# types (like 'list') do not admit serialization with the XmlSerializer (e.g. that serialization technology requires types with field setters or public default constructors or some such nonsense). I think some options that might immediately unblock you include
record list
-> record []
, etc)DataContractSerializer
instead of XmlSerializer
, as the DCS does not require as much from the type (I forget if it works with F# lists or not)Hopefully someone else more immediately familiar with .NET serialization technologies can provide a more definitive answer.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With