0

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 ?

5 Answers 5

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Use:

exc.ToString(); 

In Debug mode in Exception DialogBox, select View details option. Probably You don't implement 0-parameter constructor.

Comments

0

I think it is better to check also the stack trace and the inner exception.

You can use something like that

 string GetExceptionString(Exception ex) { string str = ""; while (ex != null) { str += ex.Message + "\n" + ex.StackTrace; ex = ex.InnerException; } return str; } 

Comments

0

Use

serExp.StackTrace 

instead of

serExp.Message.ToString() 

1 Comment

Better, serExp.ToString(), which does both of the above in one -- one of the cases where .ToString() is not a completely useless statement of the object type.
0

Set a breakpoint in the catch clause, then run in debug mode. You can then explore the exception object easier and figure out what is going on.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.