Conversation
The task NRE'd when MSBuild passed null instead of an empty array for `ResolvedReferences` — observed on vcxproj projects where `ReferencePathWithRefAssemblies` is empty/uninitialized. - Guard `ResolvedReferences` with the null-conditional operator before `SingleOrDefault`. - Audit `GetPackageInfos()` for the same class of bug: a project may have `PackageReferences` but no `ProjectAssetsFile` (legacy / non-SDK projects). Short-circuit when `LockFileUtilities.GetLockFile` returns null instead of dereferencing it. - Add unit tests that drive the task directly with null inputs (covers the vcxproj repro, all-null inputs, and PackageReferences with null ProjectAssetsFile). Adds a project reference from Tests to Tasks plus small `MockBuildEngine`/`MockTaskItem` helpers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This was referenced May 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes an
ArgumentNullExceptionfromCollectDeclaredReferencesTask.Execute()observed on Substrate vcxproj builds with ReferenceTrimmer 3.3.12+:Root cause
ResolvedReferencesis declaredITaskItem[]?but was dereferenced unconditionally on thereferenceHintPath/referenceSpecfallback path. On vcxproj projects,_ReferenceTrimmerResolvedReferences(sourced fromReferencePathWithRefAssemblies) is empty/uninitialized and MSBuild passesnullto the task instead of an empty array → NRE.Changes
CollectDeclaredReferencesTask.cs:ResolvedReferences?.SingleOrDefault(...)with the null-conditional operator.GetPackageInfos(): short-circuit whenProjectAssetsFileis null/missing and whenLockFileUtilities.GetLockFilereturns null (legacy or non-SDK projects can havePackageReferenceswithout a project.assets.json).CollectDeclaredReferencesTaskTests.cs) drive the task directly with null inputs:Referencewhose path can't be resolved locally withResolvedReferences = null.PackageReferencesnon-null withProjectAssetsFile = null.Testsproject now referencesTasksso the task can be unit-tested; smallMockBuildEngine/MockTaskItemhelpers added.All other nullable collection inputs in
Execute()(References,ProjectReferences,PackageReferences,IgnorePackageBuildFiles,TargetFrameworkDirectories) are already null-checked.