System.ArgumentException: An item with the same key has already been added. Key: vscode-merge-base
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
I am experiencing the same issue.
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)
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.
Someone reported this issue here https://github.com/microsoft/vscode/issues/244957 🤞
I have the same issue today, do we have the solution ?
A workaround is to edit .github/config file and remove the duplicate line, then Nuke has no issues.
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...
I resolved my issue by remove the github repo and reclone repo, everything worked perfect to me after do that .
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.