Here’s my class:
[Serializable()]
[XmlRootAttribute("Language")]
public class Language : ISerializable
{
string Id {
get;
set;
}
string Part2B {
get;
set;
}
string Part2T {
get;
set;
}
string Part1 {
get;
set;
}
string Scope {
get;
set;
}
string LanguageType {
get;
set;
}
string RefName {
get;
set;
}
string Comment {
get;
set;
}
snipped
I’m returning an array of them from a Mono web service, like this:
[WebMethod()]
[ScriptMethod(ResponseFormat=ResponseFormat.Json)]
public Language[] GetLanguages()
{
List<Language> languages;
languages = GetLanguageList();
return languages.ToArray();
}
But what I get is this:
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfLanguage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<Language />
<Language />
<Language />
<Language />
</ArrayOfLanguage>
Why are the members not getting serialized?
Your properties are not public.
XmlSerialization only serialises public fields and properties.
The default accessibility for fields and properties (indeed all members) is private in c#.
Also implementing ISerializable has no effect on XmlSerialization (that would be IXmlSerializable).
Neither does the [Serializable] attribute, instead you need one or more of these.