Missing int to serialize creating problems

A

ArunDhaJ

Hi,
I've a class with string and int datatypes. When trying to serialize
this class, it is missing to serialize the int field.

the class definition as follows:

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl",
"2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
myns.com/")]
public partial class myclass {
private string nameField;
private int idField;

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int id {
get {
return this.idField;
}
set {
this.idField= value;
}
}
}


when serializing the above class, the idField is getting missed. only
nameField is getting serialized.

I'm new to serialization, please help me whether I'm missing any
attributes?


Regards,
ArunDhaJ
 
A

ArunDhaJ

Hi,
I got some hint on the root cause of the problem and resolve it. The
class even has few more fields too, which I deleted in previous post.


/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("wsdl",
"2.0.50727.1432")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://
myns.com/")]
public partial class myclass {
private string nameField;
private int idField;
private bool
idFieldSpecified; /////////////////////////////////// This field
was creating the problem

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute
(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public int id {
get {
return this.idField;
}
set {
this.idField= value;
}
}
}

bool idFieldSpecified was creating the problem. When I set true to
idFieldSpecified to true, the serializer considers the idField, else
it is ignoring....

But when I searched net for such kind of feature, i couldnt find any.
Is this a feature in dot net??? please share some links if any post
explains this feature...

Thanks for your support.
Regards,
ArunDhaJ
 
P

Peter Duniho

ArunDhaJ said:
[...]
public partial class myclass {
private string nameField;
private int idField;
private bool idFieldSpecified; /////////////////////////////////// This field was creating the problem

public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}

public int id {
get {
return this.idField;
}
set {
this.idField= value;
}
}
}

bool idFieldSpecified was creating the problem. When I set true to
idFieldSpecified to true, the serializer considers the idField, else
it is ignoring....

But when I searched net for such kind of feature, i couldnt find any.
Is this a feature in dot net??? please share some links if any post
explains this feature... [...]

You should post a concise-but-complete code example that reliably
reproduces the problem.

There is no specific reason from the code you posted that some extra
field unrelated to the properties being serialized would have any
effect. I doubt anyone could copy and paste just the code you posted
and get the problem to happen.

My relatively weak psychic debugging skills suggest to me that instead,
that boolean value is actually being used somewhere to control how the
"id" property is interpreted and/or initialized. And that use is
interfering with the proper serialization or deserialization of the
property.

But without an actual concise-but-complete code example that reliably
reproduces the problem, it will not be possible to point to exactly what
you've done wrong.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top