bjorkstromm / depends

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

InvalidOperationException thrown #31

Open rockfordlhotka opened 9 months ago

rockfordlhotka commented 9 months ago

I attempted to use the tool against the main branch of the CSLA .NET project (Source/csla.build.sln) and got this exception:

dotnet depends ./csla.build.sln

Unhandled exception. System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   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 256
   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

This solution builds a wide range of projects, most UI types, class libraries, netfx, net8.0, and more. I don't see in the exception where there's any indication of which project caused the failure. Let me know if I can provide assistance.

bjorkstromm commented 9 months ago

Hi, tried reproducing. But as I don't have MAUI workload installed, I'm not even able to do the design-time build.

Platform version is not present for one or more target frameworks, even though they have specified a platform: net8.0-android, net8.0-ios, net8.0-maccatalyst Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key 'Microsoft.Maui.Controls' was not present in the dictionary.

So I don't have to install the MAUI workloads on my machine, would you mind debugging Depends for me? Place a breakpoint around here https://github.com/bjorkstromm/depends/blob/92edbd8ab6e218f8e78b59bfebd48cc27c9abd87/src/Depends.Core/DependencyAnalyzer.cs#L253-L258 and tell me the values of targetFramework, runtimeIdentifier, and lockFile.Targets 😄

rockfordlhotka commented 9 months ago

Thank you for the reply, I'll give that a try and let you know.

rockfordlhotka commented 7 months ago

targetFramework is net6.0 runtimeIdentifier is null lockFile.Targets

? lockFile.Targets[0]
{NuGet.ProjectModel.LockFileTarget}
    Libraries: Count = 21
    Name: "net6.0"
    RuntimeIdentifier: null
    TargetFramework: {net6.0}
? lockFile.Targets[1]
{NuGet.ProjectModel.LockFileTarget}
    Libraries: Count = 20
    Name: "net7.0"
    RuntimeIdentifier: null
    TargetFramework: {net7.0}
? lockFile.Targets[2]
{NuGet.ProjectModel.LockFileTarget}
    Libraries: Count = 22
    Name: "net8.0"
    RuntimeIdentifier: null
    TargetFramework: {net8.0}

The list of libraries in the net6.0 target is:

"Microsoft.Build.Tasks.Git\r\nMicrosoft.Extensions.Configuration\r\nMicrosoft.Extensions.Configuration.Abstractions\r\nMicrosoft.Extensions.Configuration.Binder\r\nMicrosoft.Extensions.DependencyInjection\r\nMicrosoft.Extensions.DependencyInjection.Abstractions\r\nMicrosoft.Extensions.FileProviders.Abstractions\r\nMicrosoft.Extensions.Hosting.Abstractions\r\nMicrosoft.Extensions.Logging.Abstractions\r\nMicrosoft.Extensions.Primitives\r\nMicrosoft.SourceLink.Common\r\nMicrosoft.SourceLink.GitHub\r\nSystem.ComponentModel.Annotations\r\nSystem.Runtime.CompilerServices.Unsafe\r\n"