PRB: You Receive a System.InvalidOperationException Error Message While You Serialize an Object That Has Two Arrays That Both Have Unqualified Items as Public Members (816224)
The information in this article applies to:
- Microsoft .NET Framework 1.1
- Microsoft .NET Framework 1.0
- Microsoft Visual C# .NET (2003)
- Microsoft Visual C# .NET (2002)
CAUSEBy using ElementName, you can make the name of the generated XML element different
from the member's identifier. When you set a single ElementName to more than one class member (that is, multiple class members
have the same ElementName), the generated XML document uses XML namespaces to distinguish
between identically named members. When the namespace is not present, you receive
the error message that is mentioned in the "Symptoms" section.WORKAROUNDTo work around this problem, add the namespace in the XmlArrayItemAttribute declaration. Because the namespace is specified, you have to set the Form property to Qualified or None as shown in the following code. Note For the sample that is described in the "More Information"
section of this article, replace the ClassToBeSerialized class with the following code: Visual C# .NETpublic class ClassToBeSerialized
{
[XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
[XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://kbarticles.com/", IsNullable=false)]
public FirstClass[] firstArrayObj = new FirstClass[2] {new FirstClass(), new FirstClass()};
[XmlArrayAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified )]
[XmlArrayItemAttribute("item", Form=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace="http://kbarticles.com/", IsNullable=false)]
public SecondClass[] secondArrayObj = new SecondClass[2] {new SecondClass(), new SecondClass()};
} Visual Basic .NETPublic Class ClassToBeSerialized
<XmlArrayAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified), _
XmlArrayItemAttribute("item", Form:=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace:="http://kbarticles.com/", IsNullable:=False)> _
Public firstArrayObj As FirstClass() = New FirstClass() {New FirstClass(), New FirstClass()}
<XmlArrayAttribute(Form:=System.Xml.Schema.XmlSchemaForm.Unqualified), _
XmlArrayItemAttribute("item", Form:=System.Xml.Schema.XmlSchemaForm.Qualified, Namespace:="http://kbarticles.com/", IsNullable:=False)> _
Public secondArrayObj As SecondClass() = New SecondClass() {New SecondClass(), New SecondClass()}
End Class STATUS This
behavior is by design.REFERENCES For additional
information about XML serialization, click the following article numbers to
view the articles in the Microsoft Knowledge Base: 323503
WebCast: XML Serialization and Sample Code
314150 INFO: Roadmap for XML Serialization in the .NET Framework
Modification Type: | Minor | Last Reviewed: | 9/5/2003 |
---|
Keywords: | kberrmsg kbXML kbSerial kbprb KB816224 kbAudDeveloper |
---|
|