posts - 236, comments - 436, trackbacks - 56

My Links

News

Awarded Microsoft MVP C#.NET - 2007, 2008 and 2009


I am born in Bangladesh and currently live in Melbourne, Australia. I am a Microsoft Certified Application Developer MCAD Chartered Member (C# .Net)and born in Bangladesh.
I am founder and Chief Executive Officer of
Simplexhub, a highly experienced software development company based in Melbourne Australia and Dhaka, Bangladesh. Co-founder and core developer of Pageflakes www.pageflakes.com.
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.


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

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)

  • Share This Post:
  • Share on Twitter
  • Share on Facebook
  • Share on Technorati

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: