Results 1 to 8 of 8

Thread: Weird error when debugging

  1. #1

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Weird error when debugging

    I am working on a project with a collegue using Source Control and i randomly get the following error when running on my machine whilst my collegue doesn't despite having the same code.

    Sometimes i can click ok and proceed as normal but other times it kicks me back into Design mode.

    It's more annoying than anything else but does anyone know what causes it or how to resolve it?

    Code:
    An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.
    
    Additional information: Object reference not set to an instance of an object.

  2. #2
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Weird error when debugging

    It basically means that you're trying to use some kind of object that is not instantiated. That's why the error is displaying a null reference exception. This error could be very tricky sometimes and my advice is to use the watch feature to see if you could find out which object is not instantiated. Somewhere you're trying to use an object that is not instantiated, just like if you're trying to use a primitive variables without declaring and instantiating that variable.

    Jennifer

  3. #3
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Weird error when debugging

    Also you could try throwing the exception to see if you could locate the object that is not instantiated. It worked for me a few times, when you find that object, you then use it AFTER it has been instantiated and then you could take out the try / catch clause. - jennifer

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Weird error when debugging

    When you get an unhandled exception you can hit the Break button and execution will halt as though you had used a breakpoint. In the case of a NullReferenceException, you can then simply test every reference (variable, property, function result) on the line until you find the one that is Nothing. You can then work backwards through your code until you find the place that you expected that object to be created. Note that you can use the Watch window to evaluate any expression you like, although there are other ways to test your references as well.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Weird error when debugging

    If i break when i hit the error i just get informed that 'there is no code available for the current location'. That would also be the problem with throwing the error - where shall i throw it from?

    As i said my collegue is running exactly the same code and not receiving the error.

    Ultimately it isn't stopping me doing anything it's just annoying.
    Last edited by Fishcake; Jan 17th, 2006 at 04:51 AM.

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Weird error when debugging

    Do you have any idea what this "Unknown Module" might be? What assemblies are you referencing?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Frenzied Member Fishcake's Avatar
    Join Date
    Feb 2001
    Location
    Derby, UK
    Posts
    1,092

    Re: Weird error when debugging

    aha! I hadn't thought of that. There are 3 non-standard references in the project which are company dll's for error handling, business logic etc. I'll look into those thanks.

    Any idea why the error is random though and will sometimes not appear and all (when it does it is before any user input before main form is displayed)?

  8. #8
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: Weird error when debugging

    IIRC, when you get the "no code available..." message, you should be able to debug as long as you have to .pdb. I guess you have the source etc. to those references as they belong to your company?

    As for why the error is random, that's a tough one - you need to figure out what's different. Could be data related - that is, you're using some data that your colleague is not. Could be something else.

    I'd try to get with the authors of those .dlls. Maybe you can work together to figure out the problem. No offense to them, but if that's the case, they need better error handling.

    You should be able to wrap a line of code in your app - maybe Application.Run in a try...catch block and get the stack trace when that error happens again. Giving the stack trace to the authors would help them alot.

    Mike

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width