423,818 Members | 2,266 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,818 IT Pros & Developers. It's quick & easy.

"xsi:type" missing from serialization of object- XmlSerializer

P: n/a
Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Dec 1 '05 #1
Share this Question
Share on Google+
6 Replies


P: n/a
And the value is it a property of type object?

Gabriel

"geoffrobinson" <ge***********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Dec 1 '05 #2

P: n/a
Here is a little more detail.

In the thing referenced in the object during the serialization is the
following:
[XmlElement(ElementName = "value")]
public ParameterValues Value;

which references this class:
[Serializable]
public class ParameterValues
{
[XmlAttribute("type")]
public string Type;

[XmlText]
public int Value;

public XParameterValues(int val)
{
Type = "xsd:int";
Value=val;
}

}

____

I'm thinking there may be some issues because an XML element references
another class. But everything seems to be serializing fine except for
the lack of the 'xsi:' before the 'type' tag.

thanks again,
Geoff

Dec 1 '05 #3

P: n/a
[XmlAttribute("type", Namespace =
"http://www.w3.org/2001/XMLSchema-instance")]
public string Type;

Gabriel Lozano-Morán
http://www.realdn.net
Dec 1 '05 #4

P: n/a
Many thanks. Worked like a charm.

Dec 1 '05 #5

P: n/a
JMD
When you manually edit in the xsi: prefix, does it actually deserialize
correctly to the Type field in the object?

This bothers me because you specified a local (not in a namespace)
attribute named 'type', which is totally distinct from the global
xsi:type which has a special meaning in XML Schemas.

So it bothers me that you never got to the bottom of why it would not
deserialize with an attribute that happens to be named 'type'. How is
that different from all the other code out there that uses
[XmlAttribute]?

Dec 6 '05 #6

P: n/a
test
"geoffrobinson" <ge***********@gmail.com> ????
news:11**********************@g43g2000cwa.googlegr oups.com...
Hi,

I'm serializing an object using XmlSerializer. It is serializing, but
we are getting errors upon deserialization.

We use the following code to serialize:

FileStream fs = new FileStream(NavCmdFile, FileMode.Create,
FileAccess.Write, FileShare.None);
XmlSerializer xmlFmt = new XmlSerializer(someObject.GetType());
xmlFmt.Serialize(fs, someObject);

One of the objects is a parameter and this is what you get:

<someObject_parameter>
<name>name</name>
<source>soucename</source>
<value type="xsd:int">1</value>
</someObject_parameter>

When we deserialize, this creates an error. When we edit one line it
deserializes correctly:
<value xsi:type="xsd:int">1</value>

Is there any other way to do this or any workaround which won't omit
the "xsi:" portion?

I appreciate any help in advance.

thanks,
Geoff

Jan 9 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.