Skip to content

Fix NRE when running sln remove#53200

Open
andbrl wants to merge 1 commit intodotnet:release/10.0.3xxfrom
andbrl:fix/nre-on-sln-remove-cmd
Open

Fix NRE when running sln remove#53200
andbrl wants to merge 1 commit intodotnet:release/10.0.3xxfrom
andbrl:fix/nre-on-sln-remove-cmd

Conversation

@andbrl
Copy link

@andbrl andbrl commented Feb 28, 2026

Hi 👋 , this PR fixes an NRE when running dotnet sln remove with a project name that doesn't exist (without extension) in the solution.

The property DisplayName is null, causing Path.GetExtensionWithoutFileName to return null leading to an NRE. So the command outputs the following:

"Object reference not set to an instance of an object."

Changing it to use ActualDisplayName fixes this and we get:

"Project 'foo' could not be found in the solution."

Running `dotnet sln remove foo` with a project name without
including the extension caused an NRE to be thrown. This
is because `DisplayName` is null. Using `ActualDisplayName`
instead fixes this.
@@ -84,7 +76,7 @@ private static async Task RemoveProjectsAsync(string solutionFileFullPath, IEnum
// If the project is not found, try to find it by name without extension
if (project is null && !Path.HasExtension(projectPath))
{
var projectsMatchByName = solution.SolutionProjects.Where(p => Path.GetFileNameWithoutExtension(p.DisplayName).Equals(projectPath));
var projectsMatchByName = solution.SolutionProjects.Where(p => p.ActualDisplayName.Equals(projectPath));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! p.DisplayName could return null

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants