This project is read-only.

Problem adding typeof(XmlIgnore) to AttributesToIgnore

Feb 16, 2012 at 7:29 PM


I am trying to use the SharpSerializer in a .net 4 WinForms application and I have everything wired up except that I need to add "XmlIgnore" to the AttributesToIgnore list so that I can use this on existing objects.  When I add this as it is outlined in the documentation, it give me the standard missing reference error.

"The type or namespace name 'XmlIgnore' could not be found (are you missing a using directive or an assembly reference?)"

I am referencing System.Xml and even have a using statement for System.Xml.Serialization, but nothing I do seems to get it to compile.

Can someone point me in the right direction?  Thanks in advance. -Christian

Feb 16, 2012 at 8:03 PM

hi, when do you get this exception? before/after/serialization/deserialization?

as the documentation you mean the following?

Feb 16, 2012 at 8:51 PM

Here is my code:

var settings = new Polenter.Serialization.SharpSerializerXmlSettings();
Polenter.Serialization.SharpSerializer serializer = new Polenter.Serialization.SharpSerializer(settings);          
serializer.Serialize(obj, "file.xml");

This will not compile because typeof(XmlIgnore) is not valid and I get the error compiler error from my initial post.

What I am trying to do is have SharpSerilizer honor the [XmlIgnore] attribute on my existing objects.  This is how it appears to be done in the documentation (as you reference in your post), but I cannot get it to compile.  Am I doing something wrong?

Thanks, -Christian


Feb 17, 2012 at 7:06 AM

hi, this works:


var settings = new SharpSerializerXmlSettings();



this works also:

var serializer = new SharpSerializer();



the only difference in your code is using XmlIgnore instead of XmlIgnoreAttribute.

Where does the XmlIgnore come from? What namespace?

Feb 17, 2012 at 11:36 AM

XmlIgnore is not a valid type at all, which is why I could not make sense of how it is used in the Tutorial on this website.

Take a look at "2. If your objects are marked with common .NET Attributes" in the "Exclude some properties from the serialization" section of the following link to see what I am referring to.  Maybe the documentation needs to be updated?

I will give XmlIgnoreAttribute a try to see if that does the trick.  Thanks! -C

Feb 17, 2012 at 11:41 AM

ups! thanks for the feedback with the documentation.

It surely does the trick ;-)

Feb 17, 2012 at 11:43 AM

No, thank you for the ridiculously fast assistance!  I really appreciate the advice.