Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I debug "Object reference not set to an instance of an object" in VS2013?

I have a c# Azure project that is just a web api, and wanted to remove some of the non-API default components (welcome page, help, etc). After doing so, when launching the application, I get an error message "Object reference not set to an instance of an object." I've seen this before when doing things in Azure, and somehow got around them each time. My question really is: how can I debug this error on my own? This error description is woefully lacking in detail (there's no call stack or anything, as if the app hasn't yet launched, and the dialog is modal so I can't click on anything within VS)

Extra notes:

  • it's an ASP .NET project.
  • it works once I publish to Azure.
  • after copying the project entirely and rebuilding, it seemed to work. then when mucking with NuGet dependencies, we're back to it not working (i've tried deleting my packages folder and having NuGet recreate - no luck; no idea if related to NuGet at all)
  • I re-copied the project, so just 'MySolutionFolder' -> 'MySolutionFolder - Copy', reopened with same version of VS, runs fine. This is an amazingly sloppy solution obviously, so looking for something better.

As described in a comment, the issue presumably dealt with access rights to various files, most likely NuGet related but possibly Azure as well, which explains why copying to a new solution directory 'fixed' the issue. I would love to see better error info, such as "Error: Visual Studio couldn't write to 'packages.config'", so I know actually where to fix this sort of issue. As it stands now, it's like a compilation error that says "Syntax error in code. Somewhere. Good luck finding it".

like image 693
Rollie Avatar asked Feb 14 '14 07:02

Rollie


3 Answers

Unfortunately, I never did discover a way to debug issues of this sort in a more general way. I eventually worked around the problem, and then saw it pop up again; following advice someone else tried on another forum, I deleted my packages folder, and had NuGet recreate it, which for whatever reason corrected the issue.

Another time, a solution from this question worked (remove and re-add all roles); sometimes this seemed to require an Azure SDK reinstall and computer restart as well.

EDIT

Finally, the best solution I could find was here: delete SUO files and restart VS.

Hopefully this solution will help someone with a similar problem in the future!

like image 123
Rollie Avatar answered Oct 31 '22 04:10

Rollie


tick Debug > Exceptions > Common Language Runtime Exceptions > System > NullReferenceException and run your app

like image 32
user626528 Avatar answered Oct 31 '22 03:10

user626528


You can enable Intellitrace and remote debug your azure services:

http://blogs.msdn.com/b/webdev/archive/2013/11/05/remote-debugging-a-window-azure-web-site-with-visual-studio-2013.aspx

like image 38
Thiago Custodio Avatar answered Oct 31 '22 03:10

Thiago Custodio