bjorkstromm / depends

Tool for generating dependency trees for .NET projects
MIT License
537 stars 41 forks source link

KeyNotFoundException for conflicts between a package reference and a project reference with the same name #34

Open remoba opened 7 months ago

remoba commented 7 months ago

I have a scenario where I have an sln with the following hierarchy:

(I realize this is not a standard practice, but I play around with MSBuild targets to copy different files from each of those dependencies)

When running dotnet depends on the sln, I am failing with this (Serilog being the placeholder ambiguous name):

Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'Serilog' was not present in the dictionary.
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
   at Depends.Core.DependencyAnalyzer.<>c__DisplayClass8_1.<CreateBuilder>b__7(ProjectItem x) in /home/runner/work/depends/depends/src/Depends.Core/DependencyAnalyzer.cs:line 328
   at System.Linq.Enumerable.WhereSelectArrayIterator`2.MoveNext()
   at Depends.Core.Graph.DependencyGraph.Builder.WithEdges(IEnumerable`1 edges) in /home/runner/work/depends/depends/src/Depends.Core/Graph/DependencyGraph.Builder.cs:line 23
   at Depends.Core.DependencyAnalyzer.CreateBuilder(IProjectAnalyzer projectAnalyzer, String projectPath, Builder builder, String framework) in /home/runner/work/depends/depends/src/Depends.Core/DependencyAnalyzer.cs:line 326
   at Depends.Core.DependencyAnalyzer.AnalyzeSolution(String solution, String framework) in /home/runner/work/depends/depends/src/Depends.Core/DependencyAnalyzer.cs:line 173
   at Depends.Program.GetDependencyGraph(ILoggerFactory loggerFactory) in /home/runner/work/depends/depends/src/Depends/Program.cs:line 132
   at Depends.Program.OnExecute() in /home/runner/work/depends/depends/src/Depends/Program.cs:line 114
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodInvoker.Invoke(Object obj, IntPtr* args, BindingFlags invokeAttr)
--- End of stack trace from previous location ---
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync[TApp](CommandLineContext context, CancellationToken cancellationToken)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args)
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](String[] args)
   at Depends.Program.Main(String[] args) in /home/runner/work/depends/depends/src/Depends/Program.cs:line 16

Not sure if this is solvable as both dependencies will ultimately produce the same dll name (I generally don't care about that because I don't consume that dll)

ErrorRepro2.zip

Attached is a simple repro of the problem, would appreciate any thoughts