Conversation
…pendency reference assembly name When TrimDepsJsonLibrariesWithoutAssets=true (now default in SDK 11.x), DependencyContextBuilder.Build() calls runtimeLibraries.ToDictionary() which crashes if two libraries share the same name. The existing fix (f1c92d6) used GetUniqueLibraryName() for the project library name, which handles conflicts with NuGet package names and with _directReferences (since GetProjectDependencies() pre-registers them). However, _dependencyReferences (from ReferenceDependencyPaths) are NOT processed by GetProjectDependencies(). If the project name matches a dependency reference assembly name (and neither is a NuGet package), both get the same unique name, causing the ToDictionary crash. Fix: After computing the unique project library name, add it to _usedLibraryNames so that subsequent GetReferenceLibraryName() calls for dependency references with the same name produce a disambiguated name. Co-authored-by: marcpopMSFT <12663534+marcpopMSFT@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
marcpopMSFT
March 13, 2026 20:20
View session
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.
https://developercommunity.visualstudio.com/t/Error-when-building-a-project-in-Microso/11045675
SDK 11.x enabled
TrimDepsJsonLibrariesWithoutAssets=trueby default, which introduced aruntimeLibraries.ToDictionary()call inDependencyContextBuilder.Build(). Any pre-existing duplicate library name inruntimeLibrariesnow causes anArgumentExceptioncrash instead of silently producing a malformed deps.json.A prior fix (
f1c92d6ca) addressed collisions between the project library name and NuGet package names (in_usedLibraryNamesat construction time) and_directReferences(pre-registered byGetProjectDependencies()). However,_dependencyReferences— assemblies fromReferenceDependencyPaths— are not processed byGetProjectDependencies(). If the project name matches one of these assembly names and neither appears as a NuGet package, both libraries receive the same name fromGetUniqueLibraryName, crashingToDictionary.Changes
DependencyContextBuilder.GetProjectRuntimeLibrary(): After computing the unique project library name viaGetUniqueLibraryName, add it to_usedLibraryNames. This ensures that when the reference loop subsequently callsGetReferenceLibraryName()for a_dependencyReferencewith the same base name, the name is detected as taken and a disambiguated name (e.g.,MyApp.Reference) is returned instead.GivenADependencyContextBuilder: Added regression testItHandlesProjectNameMatchingDirectReferenceAssemblyNameusingWithDependencyReferences(notWithDirectReferences) to exercise the specific code path that was unguarded — verifying no exception is thrown and the runtime library names are unique.