InvalidOperationException: <ClassName xmlns=''/> was not expected

Question: How do you solve error when Deserializing XML in C# Asp.Net 5: "InvalidOperationException: <ClassName xmlns=''/> was not expected"?

Solution: Do not use WebRequest API to request for XML Response, this will give you problems parsing XML instead use RestClient API to call an External Web Service then deserialize the response using XmlSerializer.

[Important]: Make sure you build your solution before requesting from a Webservice, without building your solution you might experience the same error.

- Another mistake to check is the Model you are trying to Deserialize your response in, make sure it is the right model. If not create a Model from the XML Response by going to Visual Studio "Edit" tabe menu, then "Paste Special" then "Paste XML As Classes" to create a Model classes from XML Response.

See this article

© 2024 - ErnesTech - Privacy
E-Commerce Return Policy