Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle project systems not giving us a file path #30889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,14 @@ public static uint TryGetItemId(this IVsHierarchy hierarchy, string moniker)
return VSConstants.VSITEMID_NIL;
}

public static string GetProjectFilePath(this IVsHierarchy hierarchy)
public static string TryGetProjectFilePath(this IVsHierarchy hierarchy)
{
Marshal.ThrowExceptionForHR(((IVsProject3)hierarchy).GetMkDocument((uint)VSConstants.VSITEMID.Root, out var projectFilePath));
return projectFilePath;
if (ErrorHandler.Succeeded(((IVsProject3)hierarchy).GetMkDocument((uint)VSConstants.VSITEMID.Root, out var projectFilePath)) && !string.IsNullOrEmpty(projectFilePath))
{
return projectFilePath;
}

return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public AbstractLegacyProject(
var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel));
Workspace = componentModel.GetService<VisualStudioWorkspace>();

var projectFilePath = hierarchy.GetProjectFilePath();
var projectFilePath = hierarchy.TryGetProjectFilePath();

if (projectFilePath != null && !File.Exists(projectFilePath))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ int IVsHierarchyEvents.OnPropertyChanged(uint itemid, int propid, uint flags)
propid == (int)__VSHPROPID.VSHPROPID_Name) &&
itemid == (uint)VSConstants.VSITEMID.Root)
{
var filePath = Hierarchy.GetProjectFilePath();
var filePath = Hierarchy.TryGetProjectFilePath();

if (File.Exists(filePath))
if (filePath != null && File.Exists(filePath))
{
VisualStudioProject.FilePath = filePath;
}
Expand Down