C# – Unable to Catch Specific Exception

c

I am serializing a XML File.During the serialization ,I am receiving general exception.It is hard trace the problem.

my code is:


try

{

string m_fileName = @"d:\Xml\Person.xml";

XmlSerializer xmlPerSerlzr = new XmlSerializer(typeof(person));

txtWrt = new StreamWriter(m_fileName);

xmlPerSerlzr.Serialize(txtWrt, person);

}

catch(Exception serExp)

{

MessageBox.Show("Exception is :" + serExp.Message.ToString());

}


Error Message :

There was an error reflecting type "Person"


My question is how can i force the CLR to emit the exact error ?

Best Answer

Check the type of the exception, e.g.

serExp.GetType().ToString()

and check for an inner exception (both type and message).

That should give you some more useful info.