diff --git a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs index be792ae5846cf..3bf8563fdb923 100644 --- a/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs +++ b/src/Workspaces/Core/Portable/Workspace/ProjectSystem/ProjectSystemProjectFactory.cs @@ -555,22 +555,23 @@ private static ProjectUpdateState ConvertMetadataReferencesToProjectReferences_N // PERF: call GetRequiredProjectState instead of GetRequiredProject, otherwise creating a new project // might force all Project instances to get created. var projectState = solutionChanges.Solution.GetRequiredProjectState(projectIdToRetarget); - foreach (var reference in projectState.MetadataReferences.OfType()) + foreach (var reference in projectState.MetadataReferences) { - if (string.Equals(reference.FilePath, outputPath, StringComparison.OrdinalIgnoreCase)) + if (reference is PortableExecutableReference peReference + && string.Equals(peReference.FilePath, outputPath, StringComparison.OrdinalIgnoreCase)) { - projectUpdateState = projectUpdateState.WithIncrementalMetadataReferenceRemoved(reference); + projectUpdateState = projectUpdateState.WithIncrementalMetadataReferenceRemoved(peReference); - var projectReference = new ProjectReference(projectIdToReference, reference.Properties.Aliases, reference.Properties.EmbedInteropTypes); + var projectReference = new ProjectReference(projectIdToReference, peReference.Properties.Aliases, peReference.Properties.EmbedInteropTypes); var newSolution = solutionChanges.Solution - .RemoveMetadataReference(projectIdToRetarget, reference) + .RemoveMetadataReference(projectIdToRetarget, peReference) .AddProjectReference(projectIdToRetarget, projectReference); solutionChanges.UpdateSolutionForProjectAction(projectIdToRetarget, newSolution); projectUpdateState = GetReferenceInformation(projectIdToRetarget, projectUpdateState, out var projectInfo); projectUpdateState = projectUpdateState.WithProjectReferenceInfo(projectIdToRetarget, - projectInfo.WithConvertedProjectReference(reference.FilePath!, projectReference)); + projectInfo.WithConvertedProjectReference(peReference.FilePath!, projectReference)); // We have converted one, but you could have more than one reference with different aliases that // we need to convert, so we'll keep going