microsoft / microsoft/sqlmanagementobjects
DependencyWalker.DiscoverDependencies fails with System.ArgumentException: Item has already been added.
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 143
- Forks
- 28
- PR merge metrics
- No merged PRs in 30d
Description
We hit this when we had a few old stored procedures referring to the same dropped table with different casing for database name. I see commented out code at https://github.com/microsoft/sqlmanagementobjects/blob/main/src/Microsoft/SqlServer/Management/Smo/DependencyTree.cs#L198 that might have fixed this issue, not sure why it's been commented out though.
Microsoft.SqlServer.Management.Smo.FailedOperationException: Discover dependencies failed.
---> System.ArgumentException: Item has already been added. Key in dictionary: 'Server[@Name='SERVER']/Database[@Name='database']/UnresolvedEntity[@Name='nonexisting_table' and @Schema='dbo']' Key being added: 'Server[@Name='SERVER']/Database[@Name='DATABASE']/UnresolvedEntity[@Name='nonexisting_table' and @Schema='dbo']'
at Microsoft.SqlServer.Management.Smo.DependencyTree..ctor(Urn[] urns, DependencyChainCollection dependencies, Boolean fParents, Server server)
at Microsoft.SqlServer.Management.Smo.DependencyWalker.DiscoverDependencies(Urn[] urns, Boolean parents)
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/Microsoft/SqlServer/Management/Smo/DependencyTree.cs around line 198 and trace DependencyWalker.DiscoverDependencies for how unresolved entities are keyed. Reproduce the failure with references differing only in database-name casing, then evaluate the commented-out logic. Done means dependency discovery no longer throws when equivalent unresolved references use different casing.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, sql
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100