Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: VS crashes when package sources dropdown in PM UI has multiple package sources whose names are equal when compared using Culture Ignore Case #11241

Closed
kartheekp-ms opened this issue Sep 17, 2021 · 2 comments · Fixed by NuGet/NuGet.Client#4264
Assignees
Labels
Area:Settings NuGet.Config and related issues Functionality:VisualStudioUI Package Manager UI et al Priority:2 Issues for the current backlog. Product:VS.Client Type:Bug

Comments

@kartheekp-ms
Copy link
Contributor

NuGet Product Used

Visual Studio Package Management UI

Product Version

VS 2022 and didn't test previous versions.

Worked before?

No response

Impact

Other

Repro Steps & Context

  1. Create a ClassLibrary project in Visual Studio
  2. Close the solution after it is created
  3. Add a nuget.config file with below content under solution folder.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="globalPackagesFolder" value="globalPackagesFolder" />
  </config>
  <packageSources>
    <clear />
    <add key="encyclopaedia" value="https://api.nuget.org/v3/index.json" />
    <add key="encyclopædia" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/vssdk/nuget/v3/index.json" />
  </packageSources>  
</configuration>

Note - The package source names are different when compared using ordinal ignore case and they are equal when compared using culture ignore case option.

Reference - https://docs.microsoft.com/en-us/dotnet/api/system.stringcomparison?view=net-5.0#examples

//       encyclopædia = encyclopaedia (CurrentCultureIgnoreCase): 
//       encyclopædia != encyclopaedia (OrdinalIgnoreCase): 
  1. open the solution in VS
  2. Navigate to browse tab in PM UI
  3. Change package source option to All

Actual behavior:
VS crashes

Expected behavior:
VS opens packages in the browse tab successfully

ClassLibrary38.zip

vs-crash-report

Verbose Logs

No response

@kartheekp-ms kartheekp-ms added Type:Bug Functionality:VisualStudioUI Package Manager UI et al Area:Settings NuGet.Config and related issues labels Sep 17, 2021
@kartheekp-ms
Copy link
Contributor Author

The exception message is

System.ArgumentException
HResult=0x80070057
Message=Item has already been added. Key in dictionary: 'encyclopaedia' Key being added: 'encyclopædia'
Source=mscorlib
StackTrace:
at System.Collections.SortedList.Add(Object key, Object value)
at NuGet.PackageManagement.UI.LoadingStatusViewModel.UpdateModel(IItemLoaderState loaderState)
at NuGet.PackageManagement.UI.InfiniteScrollList.<>c__DisplayClass51_0.<b__0>d.MoveNext()
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.VisualStudio.Threading.JoinableTask.CompleteOnCurrentThread()
at NuGet.PackageManagement.UI.InfiniteScrollList.HandleItemLoaderStateChange(IItemLoader1 loader, IItemLoaderState state) at System.Progress1.InvokeHandlers(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()

This exception was originally thrown at this call stack:
[External Code]

@kartheekp-ms
Copy link
Contributor Author

The fix for this issue seems to be an easy one.

Change
https://github.com/NuGet/NuGet.Client/blob/1af032a9a12c530ef434e9ea1a53cd93348e1146/src/NuGet.Clients/NuGet.PackageManagement.UI/ViewModels/LoadingStatusViewModel.cs#L25
to

var convertedList = new System.Collections.SortedList(StringComparer.OrdinalIgnoreCase);

This fix may be relevant given that we are fixing string comparision issues NuGet/NuGet.Client#4264
//cc @erdembayar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area:Settings NuGet.Config and related issues Functionality:VisualStudioUI Package Manager UI et al Priority:2 Issues for the current backlog. Product:VS.Client Type:Bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants