nuke icon indicating copy to clipboard operation
nuke copied to clipboard

System.ArgumentException: An item with the same key has already been added. Key: vscode-merge-base

Open ghost opened this issue 8 months ago • 9 comments

Usage Information

NUKE 9.0.4 / .NET SDK 9.0.203 / .NET 9.0 / Windows

Description

I'm injecting the GitRepository into my build

partial class Build : NukeBuild
{
    [GitRepository]
    readonly GitRepository Repository = null!;
}

This results in an exception.

13:06:02 [WRN] Could not inject value for Build.Repository
System.ArgumentException: An item with the same key has already been added. Key: vscode-merge-base
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector)
   at Nuke.Common.Git.GitRepository.GetRemoteNameAndBranch(AbsolutePath gitDirectory, String branch) in /_/source/Nuke.Build/VCS/GitRepository.cs:line 79
   at Nuke.Common.Git.GitRepository.FromLocalDirectory(AbsolutePath directory) in /_/source/Nuke.Build/VCS/GitRepository.cs:line 56
   at Nuke.Common.Git.GitRepositoryAttribute.GetValue(MemberInfo member, Object instance) in /_/source/Nuke.Common/Attributes/GitRepositoryAttribute.cs:line 22
   at Nuke.Common.ValueInjection.ValueInjectionAttributeBase.TryGetValue(MemberInfo member, Object instance) in /_/source/Nuke.Build/Execution/Extensibility/ValueInjectionAttributeBase.cs:line 26

This worked fine for a long time but stopped working recently, unrelated to any update. I suppose my local Git is the issue but I do not fully understand what is causing this. In my CI/CD pipeline everything works fine.

Reproduction Steps

Can't say for sure.

Expected Behavior

GitRepository would be injected with no exception.

Actual Behavior

Exception is thrown.

Regression?

No response

Known Workarounds

No response

Could you help with a pull-request?

No

ghost avatar Apr 17 '25 11:04 ghost

I am experiencing the same issue.

LilBulb1337 avatar Apr 17 '25 12:04 LilBulb1337

I can't prove is it or not Nuke related. I am not sure when that started happening and I use Nuke on almost all my projects. It appears to happen to me more often on projects I open in both VSCode and full Visual Studio. You can however edit on that project .git/config and you will see that line duplicated, removing the duplicate fixes the issue (until next time)

valadas avatar Apr 17 '25 16:04 valadas

I'm pretty sure it's unrelated to NUKE but still NUKE should handle such things gracefully. AFAIK the spec for git config files does not disallow multiple config entries for the same key.

ghost avatar Apr 17 '25 16:04 ghost

Someone reported this issue here https://github.com/microsoft/vscode/issues/244957 🤞

valadas avatar Apr 21 '25 19:04 valadas

I have the same issue today, do we have the solution ?

chuongmep avatar Jun 12 '25 12:06 chuongmep

A workaround is to edit .github/config file and remove the duplicate line, then Nuke has no issues.

valadas avatar Jun 15 '25 00:06 valadas

They (vscode repo) asl merged a PR that might fix it 2 days ago here https://github.com/microsoft/vscode/pull/251374/files it got merged into their main branch but I don't know how they manage releases, so not sure if that is fixed in Insiders or Normal release or none yet...

valadas avatar Jun 15 '25 00:06 valadas

I resolved my issue by remove the github repo and reclone repo, everything worked perfect to me after do that .

chuongmep avatar Jun 15 '25 01:06 chuongmep

This as not happened to me for a while, if others also confirm, this may no longer be an issue due to vscode fixing it.

valadas avatar Nov 21 '25 14:11 valadas