Skip to content

Handle null ProjectFile in InvalidProjectFileException#13179

Merged
ViktorHofer merged 1 commit intomainfrom
ViktorHofer-patch-1
Feb 3, 2026
Merged

Handle null ProjectFile in InvalidProjectFileException#13179
ViktorHofer merged 1 commit intomainfrom
ViktorHofer-patch-1

Conversation

@ViktorHofer
Copy link
Member

The internal InvalidProctFileException constructor accepts an existing InvalidProjectFileException object as a parameter. It passes the ProjectFile property from that passed in object to another constructor that then verifies that projectFile is not null.

Whenever an InvalidProjectFileException object is passed in that has a null projectFile (which is possible via the public ctors), an ArgumentNullException gets thrown and hides real errors.

The object gets passed to the internal ctor here:

throw new InvalidProjectFileException(ipex.Message, ipex);

Fix this by passing "MSBUILD" as a string in whenever projectFile is null.

Fixes #13150

The internal InvalidProctFileException constructor accepts an existing InvalidProjectFileException object as a parameter. It passes the ProjectFile property from that passed in object to another constructor that then verifies that projectFile is not null.

Whenever an InvalidProjectFileException object is passed in that has a null projectFile (which is possible via the public ctors), an ArgumentNullException gets thrown and hides real errors.

The object gets passed to the internal ctor here: https://github.com/dotnet/msbuild/blob/8bd4d54903169f7e515f8a32e20190b340a295c9/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs#L923

Fix this by passing "MSBUILD" as a string in whenever projectFile is null.

Fixes #13150
Copilot AI review requested due to automatic review settings February 2, 2026 13:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes a bug where InvalidProjectFileException could throw an ArgumentNullException when wrapping another InvalidProjectFileException that has a null ProjectFile property. This issue manifested non-deterministically in production builds, hiding the actual error being reported.

Changes:

  • Modified the internal constructor to use null-coalescing operator (??) to provide "MSBUILD" as a fallback value when the inner exception's ProjectFile is null

@ViktorHofer ViktorHofer merged commit 4f6355e into main Feb 3, 2026
15 checks passed
@ViktorHofer ViktorHofer deleted the ViktorHofer-patch-1 branch February 3, 2026 15:03
Copilot AI pushed a commit that referenced this pull request Feb 3, 2026
The internal InvalidProctFileException constructor accepts an existing
InvalidProjectFileException object as a parameter. It passes the
ProjectFile property from that passed in object to another constructor
that then verifies that projectFile is not null.

Whenever an InvalidProjectFileException object is passed in that has a
null projectFile (which is possible via the public ctors), an
ArgumentNullException gets thrown and hides real errors.

The object gets passed to the internal ctor here:
https://github.com/dotnet/msbuild/blob/8bd4d54903169f7e515f8a32e20190b340a295c9/src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs#L923

Fix this by passing "MSBUILD" as a string in whenever projectFile is
null.

Fixes  #13150
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.

[Unhandled Exception]: System.ArgumentNullException: Parameter "projectFile" cannot be null.

2 participants