microsoft / microsoft/sqlmanagementobjects

DependencyWalker.DiscoverDependencies fails with System.ArgumentException: Item has already been added.

Open
#148 1 comment 1 reaction 0 assignees View on GitHub

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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.