by John
26. April 2011 05:50
Hello all. I have an object model, a series of classes and whatnot, that needs to be serialized into an XML document. I have all of this working just wonderfully, except for one thing. One of the classes, called Resource, has properties for Filename, Title, Base which need to serialized as attributes named "bb:file", "bb:title" and "xml:base" respectively. When I add to the property declaration, the serializer works just fine, but if I add a 2nd one to either of the other 2 properties, I get an error stating "There was a reflection error in the serializer." - on the line where I create the serializer object; but no further information is available. test code Here is the code of the class:
<System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038"), _
System.SerializableAttribute(), _
System.Diagnostics.DebuggerStepThroughAttribute(), _
System.ComponentModel.DesignerCategoryAttribute("code"), _
System.Xml.Serialization.XmlTypeAttribute(AnonymousType:=True)> _
Partial Public Class Resource
Private fileField As String
Private titleField As String
Private identifierField As String
Private typeField As String
Private baseField As String
<System.Xml.Serialization.XmlAttributeAttribute([AttributeName]:="xml:base", Form:=System.Xml.Schema.XmlSchemaForm.Qualified)> _
Public Property base() As String
Get
Return Me.baseField
End Get
Set(ByVal value As String)
Me.baseField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Qualified)> _
Public Property file() As String
Get
Return Me.fileField
End Get
Set(ByVal value As String)
Me.fileField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Qualified)> _
Public Property title() As String
Get
Return Me.titleField
End Get
Set(ByVal value As String)
Me.titleField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property identifier() As String
Get
Return Me.identifierField
End Get
Set(ByVal value As String)
Me.identifierField = value
End Set
End Property
'''<remarks/>
<System.Xml.Serialization.XmlAttributeAttribute()> _
Public Property type() As String
Get
Return Me.typeField
End Get
Set(ByVal value As String)
Me.typeField = value
End Set
End Property
End Class
And here is the code I use to create the serializer:
Dim xmlserializor As New Xml.Serialization.XmlSerializer(GetType(BBXSD.Manifest))
Using stream As New IO.FileStream(_outputFile, IO.FileMode.OpenOrCreate, IO.FileAccess.ReadWrite)
xmlserializor.Serialize(stream, objManifest)
stream.Close()
End Using
Manifest is the "parent" class that contains a property reference to an array of Resource class objects. (this is structured this because if I use a collection or list it doesn't get serialized properly).
Any thoughts anyone has would be most welcome.