cli-lab icon indicating copy to clipboard operation
cli-lab copied to clipboard

Exception: An item with the same key has already been added

Open jonathan-meier opened this issue 4 years ago • 2 comments

I have the following two .NET Core SDK Previews installed on Windows (amongst others):

Display Name                                        - Version - Arch - Uninstall Command
Microsoft .NET Core 1.0.0 - SDK Preview 2 (x64)     - 1.0.0   - X64  - "C:\ProgramData\Package Cache\{18567b0b-ce9e-4c44-92a3-c98aba5336f6}\dotnet-dev-win-x64.1.0.0-preview2-003121.exe" /uninstall /quiet
Microsoft .NET Core 1.0.0 RC2 - SDK Preview 1 (x64) - 1.0.0   - X64  - "C:\ProgramData\Package Cache\{2adee9e7-1f53-47dc-8e30-49ff0dec528e}\dotnet-dev-win-x64.1.0.0-preview1-002702.exe" /uninstall /quiet

For both of them version 1.0.0 is extracted in RegistryQuery.GetBundleVersion leading to two different bundles with the same key 1.0.0 (x64): https://github.com/dotnet/cli-lab/blob/e07a3c995ec2d3cf449d37eb50c87e180da12544/src/dotnet-core-uninstall/Windows/RegistryQuery.cs#L95 This leads to an exception in VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings where now the two different bundles with the same key 1.0.0 (x64) are tried to be collected into a dictionary in the return statement: https://github.com/dotnet/cli-lab/blob/e07a3c995ec2d3cf449d37eb50c87e180da12544/src/dotnet-core-uninstall/Shared/VSVersioning/VisualStudioSafeVersionsExtractor.cs#L117-L119 Full exception stack trace:

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: 1.0.0 (x64)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.DotNet.Tools.Uninstall.Shared.VSVersioning.VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(IEnumerable`1 allBundles)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.GetFilteredBundlesWithRequirements(IEnumerable`1 bundles, IEnumerable`1 supportedBundleTypes, ParseResult parseResult)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.Execute(IEnumerable`1 bundles, IEnumerable`1 supportedBundleTypes)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.Execute(IBundleCollector bundleCollector)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Configs.CommandLineConfigs.<>c__DisplayClass40_0.<.cctor>b__4()
   at Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions.ExceptionHandler.<>c__DisplayClass0_0.<HandleException>b__0()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

jonathan-meier avatar Jan 15 '22 18:01 jonathan-meier

I am having this same issue with 1.0.3 (x64)

PS C:\Users\myoung> dotnet-core-uninstall list

This tool cannot uninstall versions of the runtime or SDK that are 
    - SDKs installed using Visual Studio 2019 Update 3 or later.
    - SDKs and runtimes installed via zip/scripts.
    - Runtimes installed with SDKs (these should be removed by removing that SDK).
The versions that can be uninstalled with this tool are:

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: 1.0.3 (x64)
   at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.DotNet.Tools.Uninstall.Shared.VSVersioning.VisualStudioSafeVersionsExtractor.GetReasonRequiredStrings(IEnumerable`1 allBundles)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.GetFilteredBundlesWithRequirements(IEnumerable`1 bundles, IEnumerable`1 supportedBundleTypes, ParseResult parseResult)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.Execute(IEnumerable`1 bundles, IEnumerable`1 supportedBundleTypes)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Commands.ListCommandExec.Execute(IBundleCollector bundleCollector)
   at Microsoft.DotNet.Tools.Uninstall.Shared.Configs.CommandLineConfigs.<>c__DisplayClass40_0.<.cctor>b__4()
   at Microsoft.DotNet.Tools.Uninstall.Shared.Exceptions.ExceptionHandler.<>c__DisplayClass0_0.<HandleException>b__0()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.Delegate.DynamicInvokeImpl(Object[] args)
   at System.Delegate.DynamicInvoke(Object[] args)
   at System.CommandLine.Invocation.ModelBindingCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseErrorReporting>b__21_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass25_0.<<UseVersionOption>b__0>d.MoveNext()--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass23_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__22_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseParseDirective>b__20_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseDebugDirective>b__11_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__10_0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass14_0.<<UseExceptionHandler>b__0>d.MoveNext()

maxinfet avatar Mar 31 '22 16:03 maxinfet

Same issue with dotnet-core-uninstall --version 1.5.255402+e07a3c995ec2d3cf449d37eb50c87e180da12544

Unhandled exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
 ---> System.ArgumentException: An item with the same key has already been added. Key: 1.0.0 (x64)

PeteSral avatar Jun 20 '22 13:06 PeteSral