MessageBox in Class Library
MessageBox in Class Library
am 19.12.2007 17:26:39 von 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
Re: MessageBox in Class Library
am 19.12.2007 20:29:16 von unknown
"Steve" wrote in message
news:1bhim39rffbv1538ukqq43cvtg00pt3alp@4ax.com...
> 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.
--
------------------------------------------------------------ --------------------
John Saunders | MVP - Windows Server System - Connected System Developer
Re: MessageBox in Class Library
am 19.12.2007 22:10:20 von Steve
On Wed, 19 Dec 2007 14:29:16 -0500, "John Saunders [MVP]"
wrote:
>"Steve" wrote in message
>news:1bhim39rffbv1538ukqq43cvtg00pt3alp@4ax.com...
>> 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.
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.
Re: MessageBox in Class Library
am 20.12.2007 01:32:21 von unknown
"Steve" wrote in message
news:812jm3dss527i765n8r2pldvd2vhqdohe9@4ax.com...
> On Wed, 19 Dec 2007 14:29:16 -0500, "John Saunders [MVP]"
> wrote:
>
>>"Steve" wrote in message
>>news:1bhim39rffbv1538ukqq43cvtg00pt3alp@4ax.com...
>>> 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.
>
> 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. ;-)
--
------------------------------------------------------------ --------------------
John Saunders | MVP - Windows Server System - Connected System Developer