NullReferenceException running custom tool, when there is a project that can't be loaded in the solution


Line 251 of Main-VS2010\Source\DslPackage\CustomCode\CodeGeneration\VsHelper.cs:
Diagnostics.DebugWrite("VsHelper.TryFindProjectItemAndParentProject >> Current project = '{0}'. Number of project items = {1}.", project.Name, project.ProjectItems.Count);
For projects that VS can't load, ProjectItems is null. If there is such a project in your solution that is higher up (ie. in the root of the solution or in a solution folder that is higher up), the above code throws an NullReferenceException.
I can see, that there are also instances in the Main branch where Project.ProjectItems is used wihtout a null check.

file attachments

Closed Jun 27, 2011 at 5:22 PM by andym1978
Fixed the issue and added some other null checks to potential problem areas. Fix has been committed to latest source. This issue report is a perfect example of how to submit issues. Though demus essentially reported AND provided a solution in one post, simply providing detailed info about the state of your solution, and actions taken leading up to the error, make problem solving MUCH easier. :)


andym1978 wrote Jun 27, 2011 at 4:28 PM

Interesting. I will take a look.

andym1978 wrote Jun 27, 2011 at 4:45 PM

I was able to reproduce the issue by adding a dummy project to the "Debugging" solution, then using the "Unload Project" command. The unloaded project (dimmed in gray) ends up causing the exact same problem as mentioned in this issue report. Thanks to the excellent details reported by demus, namely the location of the "unloaded" project in the solution tree, I was able to solve the issue quickly. After a few more tests, I will commit the fix to source control.

andym1978 wrote Jun 27, 2011 at 5:55 PM

Latest VSIX package with this fix for VisualStudio 2010 users.