[BUG in cf] SqlException

L

Lloyd Dupont

SqlExeption.Message is not override in CF.

I have a SqlException happening in my code

I treat it in a Global method:
OnException(Exception e)
{
string s = e.Message;
}
the message is "SqlException"
however if I cast my exception to SqlException

I have
OnException(Exeption e)
{
string s = e.Message;
if(e is SqlException)
s = ((SqlException) e).Message;
}
in this case I have a different message like "INSERT statement conflict
....."

so it seems that the Message method has not been correctly been overwrite
(with the overwrite keyword)
 
L

Lloyd Dupont

Well I discover that with the debugger.
when I try to cast to SqlException I didn't find the assembly containing the
type (??!!! not in System.Data.SqlClient ???!!!)

anyway using a bit of reflection:
PropertyInfo pi = e.GetType().GetProperty("Message", typeof(string));
return (string) pi.GetValue(e, null);

I confirm the problem
 
J

Jon Skeet [C# MVP]

Lloyd Dupont said:
SqlExeption.Message is not override in CF.

Indeed. That's a bug which I've brought up in the past too. Apparently
it'll be fixed in the next version...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top