posts - 234, comments - 480, trackbacks - 56

My Links

News




I am born in Bangladesh and currently live in Melbourne, Australia. I am a co-founder and core developer of Pageflakes www.pageflakes.com and CEO at Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Simplexhub, is on its mission to build a smart virtual community in Bangladesh and recently launched beta realestatebazaar.com.bd an ASP.NET MVC application written in C#.NET.

I also created SmartCodeGenerator

Some of my articles
Flexible and Plugin based .Net Application..
Mass Emailing Functionality with C#, .NET 2.0, and Microsoft® SQL Server 2005 Service Broker'
Write your own Code Generator or Template Engine in .NET
Smart Code Generator .NET: Usage Overview
Smart Code Generator .NET: Architectural Overview
Smart Code Generator .NET: using with NAnt and Cassini

Archives

Free Programming Language Training

Be careful using Member Name with suffix "Specified", it has special meaning to the XmlSerializer

Members with names ending on 'Specified' suffix have special meaning to the XmlSerializer: they control serialization of optional ValueType members and have to be of type System.Boolean.

Here is a test class to generate the exception where I explicitly declared the 'generating_bugSpecified' Member to integer.

[System.Xml.Serialization.XmlIncludeAttribute(typeof(TestBugg))]
public class TestBug
{

[System.Xml.Serialization.XmlAttributeAttribute()]
public System.Int32 generating_bug;
/// <remarks/>
[System.Xml.Serialization.XmlIgnoreAttribute()]
public int generating_bugSpecified;

}

Try serializing this above class with XmlSerializer, ie.

TestBug bug = new TestBug();
bug.generating_bug = 10;
SerializeObjectToFile(bug,"c:\\temp\\msg.txt");

public void SerializeObjectToFile( object objectToSerialize, string path)
{

File.Delete(path);
FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(objectToSerialize.GetType());
x.Serialize(fs, objectToSerialize);
fs.Close()

}

You will find the following exception raised.

System.InvalidOperationException: There was an error reflecting type 'WindowsApplication1.TestBug'. ---> System.InvalidOperationException: Member 'abug_genSpecified' of type System.Int32 cannot be serialized. Members with names ending on 'Specified' suffix have special meaning to the XmlSerializer: they control serialization of optional ValueType members and have to be of type System.Boolean.
at System.Xml.Serialization.FieldModel..ctor(MemberInfo memberInfo, Type fieldType, TypeDesc fieldTypeDesc)
at System.Xml.Serialization.StructModel.GetFieldModel(FieldInfo fieldInfo)
at System.Xml.Serialization.StructModel.GetFieldModel(MemberInfo memberInfo)
at System.Xml.Serialization.XmlReflectionImporter.ImportStructLikeMapping(StructModel model, String ns, Boolean openModel, XmlAttributes a)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel)
--- End of inner exception stack trace ---
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(TypeModel model, String ns, ImportContext context, String dataType, XmlAttributes a, Boolean repeats, Boolean openModel)
at System.Xml.Serialization.XmlReflectionImporter.ImportElement(TypeModel model, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlReflectionImporter.ImportTypeMapping(Type type, XmlRootAttribute root, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type, String defaultNamespace)
at System.Xml.Serialization.XmlSerializer..ctor(Type type)

Print | posted on Wednesday, July 11, 2007 12:52 PM |

Feedback

Gravatar

# re: Be careful using Member Name with suffix "Specified", it has special meaning to the XmlSerializer

Hi Shahed Khan,
Very Useful Blog. Kee updating like this.


Regards,
Selva
www.selvaonline.com
Keep Visit & Keep Grow

7/11/2007 6:09 PM | Selva
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 
 

Powered by: