Looks like primarily InvalidOperationException
.
If you go through the documentation for each of the overloads, it will give you more details. For example, see XmlSerializer.Deserialize Method (XmlReader)
The InvalidOperationException
will contain more details about the specific error in its InnerException
property.
Edit:
The XmlSerializer.Deserialize Method (XmlSerializationReader)
can throw a NotImplementedException
, but it is an internal API and is not meant to be used by your code, so don't worry about it.
Edit 2:
This code:
var ms = new System.IO.MemoryStream();
var deser = new System.Xml.Serialization.XmlSerializer(typeof(string));
deser.Deserialize(ms);
throws:
System.InvalidOperationException: There is an error in XML document (0, 0). ---
System.Xml.XmlException: Root element is missing.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
... <snip> ...
So it really looks like the framework will always throw an InvalidOperationException
.
Really, unless you're worried about mistakenly catching exceptions like ThreadAbortException
, you are probably safest catching all exceptions...
Edit 3:
Using Reflector: The Deserialize(stream)
method reads the stream using an XmlTextReader
and calls the XmlSerializer.Deserialize Method (XmlReader, String)
. That method throws an InvalidOperationException
on error (according to the docs).
Edit 4:
Deserialize(stream)
can also throw a NullReferenceException
if stream
is null, because it calls the XmlTextReader(Stream)
constructor.