This is a small bug in the automation model (EnvDTE) that I discovered yesterday when a customer of my MZ-Tools add-in reported a NullReferenceException when sorting code elements in a file outside a project:
BUG: DTE.ActiveWindow.ProjectItem.Document null for files in Solution Items folder.
http://www.mztools.com/articles/2014/MZ2014008.aspx
And here it is the bug report that I have opened at Microsoft Connect:
DTE.ActiveWindow.ProjectItem.Document null for files in Solution Items folder
https://connect.microsoft.com/VisualStudio/feedback/details/816629/dte-activewindow-projectitem-document-null-for-files-in-solution-items-folder