ssis-build icon indicating copy to clipboard operation
ssis-build copied to clipboard

ERROR: An item with the same key has already been added.

Open Mattia-Nocerino opened this issue 5 years ago • 8 comments

When trying to issue a build through Azure Devops Pipeline I get this error message: build-error

When building from Visual Studio everything works fine, all the files are the same.

This is the powershell script in the pipeline:

Get-ChildItem -Filter *.dtproj -Recurse | Where-Object { -Not ($_.FullName -match "obj") } | ForEach-Object { &"$($env:BUILD_SOURCESDIRECTORY)\SSISBuild.2.1.2\tools\ssisbuild.exe" $_.FullName -Configuration $($env:TestConfig) -ProtectionLevel DontSaveSensitive if ($LASTEXITCODE -ne 0) { throw "Build failed."; } }

Mattia-Nocerino avatar Jun 06 '19 07:06 Mattia-Nocerino

The issue occurs when project file has duplicate references to same parameters. Therefore naturally duplicate parameters cannot be added and you get generic LINQ error message.

What I would propose is to change in SsisBuild.Core.ProjectManagement.ProjectFile following lines Initialize method to

                foreach (var parameter in parameters)
                {
                    if (!_parameters.ContainsKey(parameter.Name))
                        _parameters.Add(parameter.Name, parameter);
                }

But maybe author knows how better to handle this situation.

paavels avatar Oct 08 '19 12:10 paavels

In our case it was package parameter name matching same user variable name.

paavels avatar Oct 08 '19 14:10 paavels

Hi guys, we have hit this and we cannot find the issue. We can see that the problem is in a specific dtsx file, but as soon as we add it to the project we get this build issue.

We did have a duplicate variable name with the package parameter name, but we have now deleted that but the issue still remains

Can someone tell me how I can do what the build tool is doing so I can find the duplicate issue?

o-o00o-o avatar Apr 03 '20 18:04 o-o00o-o

In our case it seems that we had two packages with the same name (in the package properties). It would be good if there was guarding on these dictionary adding to provide us with a better error message as it is very time consuming to try to find where this problem is without any clues at all

Even if there were a verbose mode so we knew what stage the code was at to get it down to a single thing we could work it out much more easily.

o-o00o-o avatar Apr 03 '20 19:04 o-o00o-o

In our case it seems that we had two packages with the same name (in the package properties). It would be good if there was guarding on these dictionary adding to provide us with a better error message as it is very time consuming to try to find where this problem is without any clues at all

Even if there were a verbose mode so we knew what stage the code was at to get it down to a single thing we could work it out much more easily.

See my comment above. You can get source, add verbose message, compile and run locally. Sorry for not having enough time to create pull request. I'm not author of this utility.

paavels avatar Apr 14 '20 18:04 paavels

I already submitted a PR for this in 2018.

https://github.com/rtumaykin/ssis-build/pull/28

bjh1977 avatar Apr 14 '20 21:04 bjh1977

When building SSIS projects using msbuild no error will be thrown if a package happens to have a name property which is the same as another in the project (this usually happens when copying packages). Go through the packages and make sure the names match the file names. I have some powershell to help with this. I'll link to it tomorrow.

bjh1977 avatar Apr 14 '20 21:04 bjh1977

Here you go: https://getitworking.net/ssis-build-an-item-with-the-same-key-has-already-been-added

bjh1977 avatar Apr 15 '20 10:04 bjh1977