How to track down "Object reference not set to an instance of an object." error when saving in Visual Studio
Eve开发者_如何学Gory time I try to save a file in VS 9 that belongs to an MVC WebSite, I get the following error dialog:
--------------------------- Microsoft Visual Studio --------------------------- Object reference not set to an instance of an object. --------------------------- OK ---------------------------
The file then gets into a weird mode where it doesn't track saves anymore (no more asterisk in its tab). Also, none of the changes get saved.
This is mind-blowingly painful as I now have to use VS2010 B2 to edit the files (but I can't load the project since 2010 wants to convert the project files themselves).
Please help!
Update I've tried attaching a debugger to VS, but cannot get it to trap on the error. I attach to the process using both the Native and Managed debuggers. I then set it to break on all first-chance exceptions (Managed, C++, Win32). However, it never breaks. I can get the useless dialog to appear at will, but I can't get a stack trace. I looked at all the native stacks while the dialog was displayed but none of them listed any plugin (mostly jest NTDLL, KERNEL32, and MSENV).
Any suggestions?
Do you have any Visual Studio Add-Ins installed? If so, I would try uninstalling them. Also does it happen when you run Visual Studio in safe-mode?
\Path\to\Visual Studio 9\Common7\IDE\devenv.exe /SafeMode
You could also attach to the devenv.exe process with another instance of Visual Studio when it throws the exception and look at the call stack to find out which dll/exe is causing the problem, but I would make sure its not a 3rd parth Add-In that's causing the problem first.
What I have done in the past is attach a new VS debugger instance to the instance of VS that you are going to replicate the problem on, making sure to have break on all errors turned on. Then replicate the error and the code that is causing the break should be shown what the application breaks on the exception.
I hope this helps.
精彩评论