Monday, February 24, 2014

Work Life: C# Web Service Errors

No spaces in name of XElement

Error Message:
System.Xml.XmlException: The ' ' character, hexadecimal value 0x20, cannot be included in a name.
This is because I had used:
XElement root = new XElement("List Of Members", e1, e2, e3);
... which should have been:
XElement root = new XElement("ListOfMembers", e1, e2, e3);

Parameterless Constructor

Error Message:
cannot be serialized because it does not have a parameterless constructor
This was because I was trying to return a variable of type XDocument which does not have a parameterless constructor. I then tried return specific classes, but still received this error because my classes did not have parameterless constructor.

Basically what the compiler is looking for is the follow:
public Class1
  { }
The constructor can also be private or internal if you do not want to have a public parameterless constructor.

No comments:

Post a Comment