1

I am sorry if this is not really a coding question (it depends on if its my code causing the problem I suppose).

I have seen this question: Tracking down intermittent 'Object reference not set to an instance of an object.' error on build

However, it has not been of much help (although if you read the comments, you will see that I thought it did help for a while there).

When I try publish my website, occasionally, I will get an error with no file or line reference:

Pre-compiling Web Site

Building directory '/App_Code/'.
Building directory '/'.: Publication (web): Object reference not set to an instance of an object.

Pre-compilation Complete
------ Skipped Publish: Project X:\, Configuration: Debug Any CPU ------

I know the usual causes of "Object reference not set to an instance of an object" but this seems a bit different, isn't it supposed to be a runtime error? Not a build error?

What is weird is that it happens, seemingly at random (about 25%-33% of the time). I can try to publish it and have it fail. Then try again straight after, without changing anything and it works fine.

I started getting this error after moving some of my functions (VB.net btw) to a new file in the App_Code folder so they can be accessed by all pages of the site.

If you need any more info, please let me know.

Thanks,

EDIT: After further investigation, it seems to only happen if I try to publish the website within a few seconds of saving changes to any file within it. What could cause this?

Community
  • 1
  • 1
Gravitate
  • 2,885
  • 2
  • 21
  • 37
  • You could try debugging Visual Studio in Visual Studio and break on NullReferenceException. You might then at least confirm which process is reporting the error. – Mark Hurd Oct 03 '12 at 05:13

4 Answers4

3

The same error occurred for me to, I deleted the dlls of the custom controls in the web site that are already in the bin, then i published the web site, and succeeded

0

IF you have any custom/usercontrols in your project, they are actually running at design time and can give object ref errors. This can occur during builds too. In that case, a property is being referenced that is NOTHING and throws the error.

U1199880
  • 907
  • 1
  • 10
  • 21
  • I am fairly sure I don't have any. What classes as a custom/usercontrol? – Gravitate Sep 13 '12 at 22:46
  • These are 3rd party design-time controls or controls that you have created, that you may have on a form. – U1199880 Sep 27 '12 at 15:10
  • Nope, definitely none of those. Just using the standard "out the box" ones. I would guess it has something to do with moving some functions into a separate class as that is when I started having the issue. Thank you for trying to help though. – Gravitate Sep 27 '12 at 16:51
  • If this is indeed the problem, how would you find it...? We have a large app with no indication of what might be throwing the error. – Timothy Lee Russell Sep 03 '13 at 18:20
  • If this is the problem, why would be intermittent? I would expect it to always fail in the same place and not succeed when you rerun. – Nelson Rothermel Jul 07 '14 at 13:48
  • Lots of reasons for intermittent. You might have a library in the solution that has been compiled that is not correctly specified in the build sequence and when deleted, the problem occurs, but once a build is rebuilt, it goes away for a while. Just a confounding variable. – U1199880 Jul 09 '14 at 13:49
0

I had a similar problem with a Windows Form project.

Wherever I try to move a custom control on the windows form, and then try to save the form, VS2010 comes back with "Object not set to an instance of an object".

I suspected the error was deep down in the layers of abstraction in my inherited code, but couldn't work out how deep to go, without reviewing every line of code.

My solution to this problem is this.

  1. Open up another instance of Visual Studio 2010
  2. Menu: Debug | Attach to Process..
  3. Search for "devenv.exe xxx YourApplicationName..." and select it
  4. Click "Attach"
  5. Menu: Debug | Exceptions..
  6. Tick all the boxes in the thrown column, then "OK"

Your second instance of VS2010 is not debugging your first instance, including all the custom controls.

Return to the first instance of VS2010, and repeat the actions that caused the error in the first place, the second instance of VS2010 will break at the line of code that has the error.

Yaroslav
  • 6,476
  • 10
  • 48
  • 89
  • Hi, thanks for your suggestion. However, when I did as you advised, the second instance did not break at all. No messages at all. Any further thoughts? – Gravitate Oct 03 '12 at 17:26