locked
null reference exception RRS feed

  • Question

  • I some times get a null reference exception in my utility programme. This utility program is started when windows is started( with the startup menu item)
    The error message is pointing to a OnActivated item, and in that part of the program (Form1_Activated) I modify The ActiveForm Text, Form1.ActiveForm.Text="modified" before it is displayed on screen.

    So it looks like that C# or runtime library is not yet "ready" to do this. Otherwise I cannot explain why it Loads with no problem and some times it fails, that is you can answer "go" and everything is ok.

    How to prevent this exception to intervene?

    I am using windows 7 home premium 64bits, vis.c# 2008 express
    Monday, January 4, 2010 10:24 PM

Answers

  • I m not sure about it, but i think that there are a way to configure the order of the assemblies to load when the SO startup. I think it could be at registry...
    Umh, If you catch the exception you could restart the try after a sleeping period(Thread.Sleep())

    Try this, and told us.

    Si la respuesta te ha sido util Marcala como Respuesta o Votala.
    Mi Blog: Jtorrecilla
    • Proposed as answer by jtorrecilla Friday, January 8, 2010 10:10 PM
    • Marked as answer by new2ceecee Monday, January 11, 2010 6:28 PM
    Monday, January 4, 2010 10:48 PM
  • Hi new2ceecee

    I think we need to see the context of the code you used, what Form1 refers to and what context it is used in the program.
    The reason could be that there was no active form of Form1, so ActiveForm returned null.

    Thanks.
    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.
    • Marked as answer by Figo Fei Monday, January 11, 2010 4:13 AM
    Thursday, January 7, 2010 3:02 AM

All replies

  • I m not sure about it, but i think that there are a way to configure the order of the assemblies to load when the SO startup. I think it could be at registry...
    Umh, If you catch the exception you could restart the try after a sleeping period(Thread.Sleep())

    Try this, and told us.

    Si la respuesta te ha sido util Marcala como Respuesta o Votala.
    Mi Blog: Jtorrecilla
    • Proposed as answer by jtorrecilla Friday, January 8, 2010 10:10 PM
    • Marked as answer by new2ceecee Monday, January 11, 2010 6:28 PM
    Monday, January 4, 2010 10:48 PM
  • Hi new2ceecee

    I think we need to see the context of the code you used, what Form1 refers to and what context it is used in the program.
    The reason could be that there was no active form of Form1, so ActiveForm returned null.

    Thanks.
    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.
    • Marked as answer by Figo Fei Monday, January 11, 2010 4:13 AM
    Thursday, January 7, 2010 3:02 AM