Probably you're messing up the names of enumeration members with their underlying integer values. Look at the sample of usage if this attribute here:
http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlenumattribute.aspx[
^].
The serialization mechanism for enumeration is based of enumeration member identifiers, not underlying integer values. The values or the
XmlEnum
attribute should be valid and unique member identifiers, but "1", "2" are not. To assign integer values you need you should do something like this:
public enum OriginTypeCode
{
Item1 = 1,
Item2 = 2,
}
Also, there is no boundary between C++/CLI and C#. If you define any enumeration type in an assembly written in any of these languages and reference this assembly in another assembly written in any of these language, the declarations will be interpreted in exact same way, including those underlying integer values.
When you use serialized presentation of your data, the file/stream written using by one of the languages, will be correctly read by the assembly written in a different language, because they share the same enumeration type declaration and because the enumeration members are identified by their names. This is an feature important for compatibility between versions: if you add/insert additional enumeration member in your enumeration types, existing members from your legacy data will be interpreted by new version of your sofrware semantically, which is usually what you want.
The mapping between enumeration members and their respective underlying integer values is actually a very delicate matter and a source of some subtle problems (but features, too). To understand this, please read my article on the topic:
Enumeration Types do not Enumerate! Working around .NET and Language Limitations[
^]. I explain it in detail.
There is no need to use
System.Xml.Serialization.XmlEnumAttribute
in your case. (By the way, recommended practice is using abbreviated name at the point of attribute application: [
XmlEnum
] instead of [
XmlEnumAttribute
].) One of the uses of this attribute it to give enumeration members more descriptive names when it it not possible to do it in the source code; another use is using serialization for integration with a legacy system which cannot be modified.
—SA