Avatar of pointeman
Flag for United States of America asked on

Class Library Delegate and Event Issues?

I usually built a Class Libary within a Windows Forms project. I can test the class by using buttons and textboxes. I send the 'Status' messages to Form1 using a Delegate and Event as illustrated in the code example below. The problem arises when deploying the Class Libarary to be used with another executable. The unused Delegate causes an 'Object Reference' error if it's not instanctiated in the new executable. I want the option for class library status message returns if needed, but don't want to demand the delegate instanciation.

   [class library (.dll)]
   public delegate void JobManagerStatusEventHandler(string statusMessage);

    public static class JobSetup
        public static event JobManagerStatusEventHandler StatusMessage;

Avatar of undefined
Last Comment

8/22/2022 - Mon
Haver Ramirez

then, you must initialice the object in your dll

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Haver Ramirez

you must create the object, because the class is static is created in memory and you must create one instance for related objects


Q, Anyway to use a cool ?? operator instead?

        StatusMessage(??  : "Hello World!");
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.

Cool, thanks again