MessageBox in Class Library

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    #1

    MessageBox in Class Library

    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
  • John Saunders [MVP]

    #2
    Re: MessageBox in Class Library

    "Steve" <kilroy@harpser vices.comwrote in message
    news:1bhim39rff bv1538ukqq43cvt g00pt3alp@4ax.c om...
    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


    Comment

    • Steve

      #3
      Re: MessageBox in Class Library

      On Wed, 19 Dec 2007 14:29:16 -0500, "John Saunders [MVP]"
      <john.saunder s at trizetto.comwro te:
      >"Steve" <kilroy@harpser vices.comwrote in message
      >news:1bhim39rf fbv1538ukqq43cv tg00pt3alp@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.

      Comment

      • John Saunders [MVP]

        #4
        Re: MessageBox in Class Library

        "Steve" <kilroy@harpser vices.comwrote in message
        news:812jm3dss5 27i765n8r2pldvd 2vhqdohe9@4ax.c om...
        On Wed, 19 Dec 2007 14:29:16 -0500, "John Saunders [MVP]"
        <john.saunder s at trizetto.comwro te:
        >
        >>"Steve" <kilroy@harpser vices.comwrote in message
        >>news:1bhim39r ffbv1538ukqq43c vtg00pt3alp@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


        Comment

        Working...