madskristensen / SolutionColors

A Visual Studio extension
Apache License 2.0
77 stars 10 forks source link

Automatic coloring does not work in some cases #40

Closed Arkane5 closed 8 months ago

Arkane5 commented 8 months ago

For one of my solutions, automatic color does not work (no color is displayed). Manually choosing a color works.

Affected version 1.1.65

To Reproduce Steps to reproduce the behavior:

  1. Open a specific solution (see end of additional context, below)
  2. See error (no color, and exception in output window)

Expected behavior The solution has a color.

Additional context The following exception stack trace is displayed in output/Extensions:

System.AggregateException: One or more errors occurred. ---> System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index at System.Linq.Enumerable.ElementAt[TSource](IEnumerable`1 source, Int32 index) at SolutionColors.ColorCache.GetColor(String filePath) in D:\a\SolutionColors\SolutionColors\src\ColorCache.cs:line 57 at SolutionColors.ColorHelper.d16.MoveNext() in D:\a\SolutionColors\SolutionColors\src\ColorHelper.cs:line 273 --- 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 SolutionColors.ColorHelper.d9.MoveNext() in D:\a\SolutionColors\SolutionColors\src\ColorHelper.cs:line 109 --- 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 SolutionColors.SolutionColorsPackage.<b__6_0>d.MoveNext() in D:\a\SolutionColors\SolutionColors\src\SolutionColorsPackage.cs:line 77 --- End of inner exception stack trace --- ---> (Inner Exception #0) [eluded, repeat of the above]

After reading the source code of the extension, I noticed that the problem went away if I renamed the solution or changed a part of its path, but came back with the original path/name. I suppose that there is an issue with the hash code of that solution's path. As this is a professional project, I don't think I can publicly share its path. If I didn't mess up, its hash code should be 1196983195.

I just realized I think I understand the issue. In ColorCache.GetColor, Shouldn't : int mod = hash % ColorMap.Count - 1; be int mod = hash % (ColorMap.Count - 1); instead?

Arkane5 commented 8 months ago

Fixed with v1.1.67