troubleshooting Question

C# assignment results in null reference

Avatar of tbragsda
tbragsda asked on
.NET ProgrammingC#
2 Comments1 Solution406 ViewsLast Modified:
Here is a portion of a User Control class, UserControlTask:

    public interface ITaskItem
        void Run();
        bool Check();
        string buttonText { get; }
        string itemID { get; }
        Form1 daddy { get; set; }
        ProgressBar pb { get; set; }

    public partial class UserControlTask<T> : UserControl where T : ITaskItem, new()
        T t;
        public delegate void Run_();
        public Run_ Run;
        public delegate bool Check_();
        public Check_ Check;

        public string itemID;

        private Form1 daddy;

        public UserControlTask(Form1 sender, int y)
            Top = y;
            t = new T();
            itemID = t.itemID;

            daddy = sender;

            t.daddy = sender;        /* <- problem here */
            t.pb = this.progressBarTask;    /* <- problem here */

            Run = new Run_(t.Run);
            Check = new Check_(t.Check);
            buttonTask.Text = t.buttonText;

progressBarTask is a Progress Bar in the user control. You can see that I instantiate an object of type T and use accessors to save references to my main form, and to progressBarTask in the user control. However, instead, both t.daddy and t.pb evaluate to null after the assignment (where "problem here" is commented). The object is derived from a class Task, which contains the accessors:

    abstract class Task : ITaskItem
        private Form1 daddy_;
        private ProgressBar pb_;
        public SqlConnection conn = new SqlConnection("server=x;user=x;password=x");

        public Task()

        protected string itemID_;
        protected string buttonText_;

        public Form1 daddy
            get { return daddy_; }
            set { daddy_ = daddy; }

        public ProgressBar pb
            get { return pb_; }
            set { pb_ = pb; }

        public string itemID
            get { return itemID_; }

        public string buttonText
            get { return buttonText_; }

        public abstract void Run();
        public abstract bool Check();

...SO... why is it that I can't make that assignment?
Join the community to see this answer!
Join our exclusive community to see this answer & millions of others.
Unlock 1 Answer and 2 Comments.
Join the Community
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros