MessageBox in Class Library

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi All,

I'm writing an error handler and need to display a MessageBox from
within a Class Library. I've added System.Windows.Forms as a
reference and also to my using list. The compiler complains that "The
type or namespace name 'Windows' does not exist in the namespace
'System'.

What could I be doing wrong?

Thanks,
Steve
 
Steve said:
Hi All,

I'm writing an error handler and need to display a MessageBox from
within a Class Library. I've added System.Windows.Forms as a
reference and also to my using list. The compiler complains that "The
type or namespace name 'Windows' does not exist in the namespace
'System'.

You need to add a reference to System.Windows.Forms.dll.

Also, are you sure you want to be displaying a message box from your class
library? It would be more general if you were to throw an exception, and
allow your callers to decide whether or not to display a message box. What
would happen if your class library were called from a Web Service, for
instance? If the message box displayed at all, it would display on the
server, and the client would never find out that there was a problem.
 
You need to add a reference to System.Windows.Forms.dll.

Also, are you sure you want to be displaying a message box from your class
library? It would be more general if you were to throw an exception, and
allow your callers to decide whether or not to display a message box. What
would happen if your class library were called from a Web Service, for
instance? If the message box displayed at all, it would display on the
server, and the client would never find out that there was a problem.

As I mentioned in my original post, " I've added System.Windows.Forms
as a reference". This class doesn't throw an exception because it's
an error handler. I'm passing thrown exceptions to it. The class has
the option (set by the user) to log the exception and/or display it.
 
Steve said:
As I mentioned in my original post, " I've added System.Windows.Forms
as a reference". This class doesn't throw an exception because it's
an error handler. I'm passing thrown exceptions to it. The class has
the option (set by the user) to log the exception and/or display it.

Sorry, didn't see "System.Windows.Forms", for some reason.

I can't imagine how you'd get that error message if you have a good
reference to System.Windows.Forms.dll in your project.

And, BTW, in the future, I'll try to remember that you understand exception
handling. ;-)
 
Back
Top