This project has moved and is read-only. For the latest updates, please go here.


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 6: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 5:28 PM

Interesting. I will take a look.

andym1978 wrote Jun 27, 2011 at 5: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.

wrote Jun 27, 2011 at 6:14 PM

wrote Jun 27, 2011 at 6:22 PM

wrote Jun 27, 2011 at 6:55 PM

andym1978 wrote Jun 27, 2011 at 6:55 PM

Latest VSIX package with this fix for VisualStudio 2010 users.

wrote Feb 22, 2013 at 12:30 AM

wrote May 16, 2013 at 12:04 PM