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

An error occured while loading the Resource Explorer: An item with the same key has already been added. #9523

Closed
WolfgangHG opened this issue Aug 15, 2024 · 2 comments

Comments

@WolfgangHG
Copy link

WolfgangHG commented Aug 15, 2024

This error happens when opening a resx file with the new Resource Explorer in Visual Studio 17.11.0:
resourceexplorer_error

System.ArgumentException: An item with the same key has already been added.
   at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
   at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
   at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
   at Microsoft.VisualStudio.ResourceExplorer.Utils.DisplayPathUtils.GetResourceGroupTreeNodeName(String baseName, Project project, ImmutableArray`1 parseResults)
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel.CreateResourceGroupNode(HashSet`1 nodesToCheck, SolutionContext solutionContext, ResourceGroupParseResult resourceGroupParseResult, ResourceTreeNode projectNode, ImmutableArray`1 projectParseResults)
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel.<>c__DisplayClass10_0. <CreateProjectNode>b__2(ResourceGroupParseResult result)
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel.<>c__DisplayClass10_0. <CreateProjectNode>g__AddChildNodesToProjectNode|1()
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel.CreateProjectNode(HashSet`1 nodesToCheck, ProjectContext projectContext, ProjectUpdateType update)
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel. <OnProjectUpdate>g__HandleProjectAdded|8_0(ProjectContext projectContext, ProjectUpdate update)
   at Microsoft.VisualStudio.ResourceExplorer.UI.NavTree.NavigationTreeViewModel.OnProjectUpdate(ProjectUpdate update)
   at Microsoft.VisualStudio.ResourceExplorer.SolutionContext.NotifyProjectAdded(ProjectContext projectContext)
   at Microsoft.VisualStudio.ResourceExplorer.IO.SolutionLoader. <HandleProjectLoadAsync>d__5.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ResourceExplorer.IO.SolutionLoader. <LoadSolutionAsync>d__4.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ResourceExplorer.UI.ResourceExplorerControl.<>c__DisplayClass2_0. <<TryPopulateSolution>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.ResourceExplorer.UI.AsyncLoadContent.<>c__DisplayClass0_0. <<Initialize>b__0>d.MoveNext()

We have a large solution (about 100 projects) with a lot of resx files with string values or images. We also have “Properties\Resources.resx” files in most projects. But the issue also happens when opening a WinForms resx file.

I tried to reproduce it with a small sample, but did not succeed. So it must be related to the size of the solution or something special.

Workaround: right click on resx file => “Open with” ==> “Managed Resources Editor (Legacy)”.

While debugging VS, I noticed a lot of FileNotFoundExceptions like this - don’t know whether they are related:

System.IO.DirectoryNotFoundException
  HResult=0x80070003
  Message=Could not find a part of the path 'E:\Projekte\Tools\DEV\DLLs\HG. ApplicationBase.Guiwin\Web\Controls\Resources\nav_refresh_blue_16x16.ico'.
  Source=mscorlib
  StackTrace:
   at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) in System.IO\__Error.cs:line 135

>	mscorlib.dll! System.IO.__Error.WinIOError(int errorCode, string maybeFullPath) Line 133	C#
 	mscorlib.dll! System.IO.FileStream.Init(string path, System.IO.FileMode mode, System.IO.FileAccess access, int rights, bool useRights, System.IO.FileShare share, int bufferSize, System.IO.FileOptions options, Microsoft.Win32.Win32Native.SECURITY_ATTRIBUTES secAttrs, string msgPath, bool bFromProxy, bool useLongPath, bool checkHost) Line 710	C#
 	mscorlib.dll! System.IO.FileStream.FileStream(string path, System.IO.FileMode mode, System.IO.FileAccess access, System.IO.FileShare share) Line 352	C#
 	System.Windows.Forms.dll! System.Resources.ResXFileRef.Converter.ConvertFrom(System.ComponentModel.ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)	Unknown
 	System.Windows.Forms.dll! System.Resources.ResXDataNode.GetValue(System.ComponentModel.Design.ITypeResolutionService typeResolver)	Unknown
 	Microsoft.VisualStudio.ResourceExplorer.dll! Microsoft.VisualStudio.ResourceExplorer.IO.ResxResourceParser.GetNodeValue(string path, System.Resources.ResXDataNode node) Line 239	C#
 	Microsoft.VisualStudio.ResourceExplorer.dll! Microsoft.VisualStudio.ResourceExplorer.IO.ResxResourceParser.TryParseNodeValue(string localizedPath, System.Resources.ResXDataNode node) Line 217	C#
 	Microsoft.VisualStudio.ResourceExplorer.dll! Microsoft.VisualStudio.ResourceExplorer.IO.ResxResourceParser.ParseGroup(Microsoft.VisualStudio.ResourceExplorer.IO.ResourceGroupParseResult existingParseResult, string baseName, string neutralFilePath, System.Collections.Immutable.ImmutableArray<(string Path, string Culture)> localizablePaths, System.Collections.Generic.IReadOnlyCollection<string> selectedGroupBasePaths, Microsoft.VisualStudio.ResourceExplorer.IO.IRdtDocumentManager rdtDocumentManager, Microsoft.VisualStudio.ResourceExplorer.Model.Project project, System.Threading.CancellationToken token, out System.Collections.Immutable.ImmutableDictionary<string, Microsoft.VisualStudio.ResourceExplorer.Model.ResourceFileLoadException> loadExceptionsByCulture, out Microsoft.VisualStudio.ResourceExplorer.Model.ResourceFileType resourceFileType) Line 87	C#
 	Microsoft.VisualStudio.ResourceExplorer.dll! Microsoft.VisualStudio.ResourceExplorer.IO.Resx.ProjectResourceLoader.ParseGroup(Microsoft.VisualStudio.ResourceExplorer.IO.ResourceGroupParseResult existingParseResult, string baseName, string neutralFilePath, System.Collections.Immutable.ImmutableArray<(string Path, string Culture)> localizedFiles, System.Collections.Generic.IReadOnlyCollection<string> selectedGroupBasePaths, bool? shouldBeSelected, Microsoft.VisualStudio.ResourceExplorer.Model.Project project, Microsoft.VisualStudio.ResourceExplorer.IO.IRdtDocumentManager rdtDocumentManager, System.Threading.CancellationToken token) Line 48	C#
 	Microsoft.VisualStudio.ResourceExplorer.dll! Microsoft.VisualStudio.ResourceExplorer.IO.SolutionLoader.LoadInitialFilesInProjectAsync.AnonymousMethod__3(Microsoft.VisualStudio.ResourceExplorer.IO.ResxFileGrouping group) Line 160	C#
 	System.Core.dll! System.Linq.Parallel.SelectQueryOperator<System.__Canon, System.__Canon>. SelectQueryOperatorEnumerator<int>. MoveNext(ref System.__Canon currentElement, ref int currentKey)	Unknown
 	System.Core.dll! System.Linq.Parallel.PipelineSpoolingTask<System.__Canon, int>. SpoolingWork()	Unknown
 	System.Core.dll! System.Linq.Parallel.SpoolingTaskBase.Work()	Unknown
 	System.Core.dll! System.Linq.Parallel.QueryTask.BaseWork(object unused)	Unknown
 	mscorlib.dll! System.Threading.Tasks.Task.Execute() Line 2514	C#
 	mscorlib.dll! System.Threading.ExecutionContext.RunInternal(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 515	C#
 	mscorlib.dll! System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext executionContext, System.Threading.ContextCallback callback, object state, bool preserveSyncCtx) Line 486	C#
 	mscorlib.dll! System.Threading.Tasks.Task.ExecuteWithThreadLocal(ref System.Threading.Tasks.Task currentTaskSlot) Line 2684	C#
 	mscorlib.dll! System.Threading.Tasks.Task.ExecuteEntry(bool bPreventDoubleExecution) Line 2630	C#
 	mscorlib.dll! System.Threading.ThreadPoolWorkQueue.Dispatch() Line 569	C#

Interesting here is that “nav_refresh_blue_16x16.ico” is declared in “E:\Projekte\Tools\DEV\DLLs\Personenpool\PersonenpoolGui\PersonenpoolGui.csproj\Properties\Resources.resx”:

  <data name="nav_refresh_blue_16x16" type="System.Resources.ResXFileRef, System.Windows.Forms">
    <value>.. \Controls\Resources\nav_refresh_blue_16x16.ico; System.Drawing.Bitmap, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a</value>
  </data>

The directory “E:\Projekte\Tools\DEV\DLLs\HG. ApplicationBase.Guiwin\Web\Controls” does not exist. So, maybe some current path is not properly reset when traversing the solution?
The solution is placed at “E:\Projekte\Tools\DEV”, and all projects are in “E:\Projekte\Tools\DEV\DLLs”, some in sub directories.

Unfortunately, I cannot watch variable values while debugging, so I cannot provide more details.

@WolfgangHG
Copy link
Author

@haileymck
Copy link
Contributor

Hi @WolfgangHG, thank you for filing a Feedback ticket. We will continue to track the issue there. I will close this issue as to not have duplicate issues, so please follow up on the other ticket with further discussion. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants