private bool IsSupportedProject(ITextBuffer textBuffer) { // Fundamentally we have a Razor half of the world as soon as the document is open - and then later // the C# half of the world will be initialized. This code is in general pretty tolerant of // unexpected /impossible states. // // We also want to successfully shut down if the buffer is something other than .cshtml. object project = null; var isSupportedProject = false; // We expect the document to have a hierarchy even if it's not a real 'project'. // However the hierarchy can be null when the document is in the process of closing. if ((project = _projectService.GetHostProject(textBuffer)) != null) { isSupportedProject = _projectService.IsSupportedProject(project); } return(isSupportedProject); }