locked
System.NullReferenceException set_& Visible RRS feed

  • Question

  • Hello,

    I am getting the below error while using notifyicon control of windows.forms

    System.NullReferenceException: Object reference not set to an instance of an object. at System.Windows.Forms.NotifyIcon.UpdateIcon(Boolean showIconInTray) at System.Windows.Forms.NotifyIcon.set_Visible(Boolean value)

    If anyone is having any idea about the above ,.... please let me know.

    Thanks
    VChauhan
    • Moved by Zhi-Xin Ye Wednesday, April 1, 2009 9:38 AM not a BCL question
    Thursday, March 26, 2009 11:01 AM

All replies

  • This error may be because you didn't specify the icon for the NotifyIcon control. Please check the icon property in the NotifyIcon properties and if there it is missing, specify one and check
    -- Thanks Ajith R
    Thursday, March 26, 2009 11:18 AM
  • Hey thanks for the reply

    but we have already assign icon to the notifyIcon control

    also we are not getting this error frequently but it does some time, we couldn't identify when???

    please help, we are stuck on the error

    thanks in advance
    Thursday, March 26, 2009 11:31 AM
  • Can you please tell me the exact scenario of getting the error. and please provide the code sniplet where the error happends(if you are able to)
    -- Thanks Ajith R
    Thursday, March 26, 2009 12:04 PM
  • actually we have a windows application (c#) that polled data from the attached device

    this application has been sent to the system tray when user minimizes the applicaiton. on live environment this error occurs which we could not debug, user can restore the application while double click on the icon set at systemtray

    we are unable to generate them locally so could not able to tell you the exact scenario
    Thursday, March 26, 2009 12:09 PM
  • Hello,

    if you wants to generate this problem, just call the close() method of a form and then call that
    Notifyicon.visible = true line ... you will get the above error.

    for its solution, dont close the form as it will remove all the properties of the control.

    Try that or let me know.


    • Proposed as answer by CVin Wednesday, April 1, 2009 9:33 AM
    Thursday, March 26, 2009 1:22 PM
  • Hi,

    I try the following code and cannot reproduce the problem you described,

    private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
                this.notifyIcon1.Visible = true;
            }

    By the way, please use this forum Base Class Library questions, this question is better posted at Windows Forms forums http://social.msdn.microsoft.com/Forums/en-US/winforms/threads.

    Best Regards,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, March 31, 2009 12:44 PM
  • Hello,

    For the above code ...

    private void button1_Click(object sender, EventArgs e)
            {
                this.notifyIcon1.Visible = true;
            }

    after             this.Close();, if you will try to check the icon property of  notify icon that is


    this.notifyIcon1.Icon = .....

    then you will get the specified error as on close method call, it will remove the icon property of notify icon control.

    :) try that ....

    • Proposed as answer by CVin Wednesday, April 1, 2009 9:30 AM
    Wednesday, April 1, 2009 4:12 AM
  • Hi,

    I can reproduce it now with the following code:

    private void button1_Click(object sender, EventArgs e)
            {
                this.Close();
                this.notifyIcon1.Icon = SystemIcons.Application;
            }

    However, does it make sense to set the Icon property after closing the form? You can use Form.Hide() method instead.

    Best Regards,


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Wednesday, April 1, 2009 6:18 AM
  • hi,

    thats true but i have to close my form ... dont hide that form so i had placed close method but on that i got such error ......
    • Marked as answer by vchauhan Wednesday, April 1, 2009 6:42 AM
    • Unmarked as answer by vchauhan Wednesday, April 1, 2009 7:15 AM
    • Proposed as answer by CVin Wednesday, April 1, 2009 9:32 AM
    Wednesday, April 1, 2009 6:42 AM