bjorkstromm / depends

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

Crashes on net472 project #4

Closed twenzel closed 5 years ago

twenzel commented 5 years ago
dbug: Buildalyzer.Environment.ProcessRunner[0]

      Started process 14892: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"  /noconsolelogger /target:Restore /property:ProvideCommandLineArgs="true";GenerateResourceMSBuildArchitecture="CurrentArchitecture";DesignTimeBuild="true";BuildProjectReferences="false";SkipCompilerExecution="true";DisableRarCache="true";AutoGenerateBindingRedirects="false";CopyBuildOutputToOutputDirectory="false";CopyOutputSymbolsToOutputDirectory="false";SkipCopyBuildProduct="true";AddModules="false";UseCommonOutputDirectory="true";GeneratePackageOnBuild="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";ResolveNuGetPackages="true";SolutionDir="C:\Data\GIT\Framework\Applications\Demo\CHG.Demo.AppServer" /l:BuildalyzerLogger,"C:\Users\dtw\.dotnet\tools\.store\dotnet-depends\0.2.0\dotnet-depends\0.2.0\tools\netcoreapp2.1\any\Buildalyzer.Logger.dll";980;False "C:\Data\GIT\Framework\Applications\Demo\CHG.Demo.AppServer\CHG.Demo.AppServer.csproj"

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Framework

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Copyright (C) Microsoft Corporation. All rights reserved.

dbug: Buildalyzer.Environment.ProcessRunner[0]

dbug: Buildalyzer.Environment.ProcessRunner[0]

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Process 14892 exited with code 0

dbug: Buildalyzer.Environment.ProcessRunner[0]

      Started process 26268: "C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe"  /noconsolelogger /target:Clean;Build /property:ProvideCommandLineArgs="true";GenerateResourceMSBuildArchitecture="CurrentArchitecture";DesignTimeBuild="true";BuildProjectReferences="false";SkipCompilerExecution="true";DisableRarCache="true";AutoGenerateBindingRedirects="false";CopyBuildOutputToOutputDirectory="false";CopyOutputSymbolsToOutputDirectory="false";SkipCopyBuildProduct="true";AddModules="false";UseCommonOutputDirectory="true";GeneratePackageOnBuild="false";NonExistentFile="__NonExistentSubDir__\__NonExistentFile__";ResolveNuGetPackages="true";SolutionDir="C:\Data\GIT\Framework\Applications\Demo\CHG.Demo.AppServer" /l:BuildalyzerLogger,"C:\Users\dtw\.dotnet\tools\.store\dotnet-depends\0.2.0\dotnet-depends\0.2.0\tools\netcoreapp2.1\any\Buildalyzer.Logger.dll";1032;False "C:\Data\GIT\Framework\Applications\Demo\CHG.Demo.AppServer\CHG.Demo.AppServer.csproj"

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Microsoft (R) Build Engine version 15.8.169+g1ccb72aefa for .NET Framework

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Copyright (C) Microsoft Corporation. All rights reserved.

dbug: Buildalyzer.Environment.ProcessRunner[0]

dbug: Buildalyzer.Environment.ProcessRunner[0]

dbug: Buildalyzer.Environment.ProcessRunner[0]
      Process 26268 exited with code 0
Unhandled Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidOperationException: Sequence contains more than one matching element
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at Depends.Core.DependencyAnalyzer.Analyze(String projectPath, String framework) in C:\Users\mb\src\gh\depends\src\Depends.Core\DependencyAnalyzer.cs:line 205
   at Depends.Program.OnExecute()
   --- End of inner exception stack trace ---
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.Invoke(MethodInfo method, Object instance, Object[] arguments) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 86
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.OnExecute(ConventionContext context) in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 64
   at McMaster.Extensions.CommandLineUtils.Conventions.ExecuteMethodConvention.<>c__DisplayClass0_0.<<Apply>b__0>d.MoveNext() in C:\projects\commandlineutils\src\CommandLineUtils\Conventions\ExecuteMethodConvention.cs:line 25
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.<>c__DisplayClass126_0.<OnExecute>b__0() in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.cs:line 505
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](CommandLineContext context) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 31
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.Execute[TApp](IConsole console, String[] args) in C:\projects\commandlineutils\src\CommandLineUtils\CommandLineApplication.Execute.cs:line 97
   at Depends.Program.Main(String[] args) in C:\Users\mb\src\gh\depends\src\Depends\Program.cs:line 16

This is my csporj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>       
    <TargetFramework>net472</TargetFramework>
    <GenerateAssemblyInfo>false</GenerateAssemblyInfo>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
        <LangVersion>latest</LangVersion>  
    <OutputPath>..\..\..\bin\Demo\Server</OutputPath>    
    <OutputType>Exe</OutputType>    
  </PropertyGroup>
  <ItemGroup>
    <None Remove="NServiceBusLicense.xml" />
  </ItemGroup>
  <ItemGroup>
    <Compile Include="..\..\..\CHG.iCLASSFW.AssemblyInfo.cs" Link="CHG.iCLASSFW.AssemblyInfo.cs" />    
  </ItemGroup>
  <ItemGroup>
    <Content Include="appsettings.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
    <Content Include="NServiceBusLicense.xml">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Base.Foundation\CHG.iCLASSFW.Base.Foundation.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Base.Managers\CHG.iCLASSFW.Base.Managers.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Base.Objects\CHG.iCLASSFW.Base.Objects.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.ExchangeConnector.Managers\CHG.iCLASSFW.ExchangeConnector.Managers.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Export.Jobs\CHG.iCLASSFW.Export.Jobs.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Export.Managers\CHG.iCLASSFW.Export.Managers.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.PrintReporting.Managers\CHG.iCLASSFW.PrintReporting.Managers.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.UDM.Managers\CHG.iCLASSFW.UDM.Managers.vbproj" />
    <ProjectReference Include="..\..\..\CHG.iCLASSFW.Windsor\CHG.iCLASSFW.Windsor.vbproj" />
    <ProjectReference Include="..\..\..\src\Base\CHG.iCLASSFW.Log4Net\CHG.iCLASSFW.Log4Net.csproj" />
    <ProjectReference Include="..\..\..\src\Base\CHG.iCLASSFW.NServiceBus\CHG.iCLASSFW.NServiceBus.csproj" />
    <ProjectReference Include="..\..\..\src\Corporate\CHG.iCLASSFW.Corporate.Server\CHG.iCLASSFW.Corporate.Server.csproj" />
    <ProjectReference Include="..\..\..\src\Exchange\CHG.iCLASSFW.ExchangeConnector.Server\CHG.iCLASSFW.ExchangeConnector.Server.csproj" />
    <ProjectReference Include="..\..\..\src\Maintenance\CHG.iCLASSFW.Maintenance.Managers\CHG.iCLASSFW.Maintenance.Managers.csproj" />
    <ProjectReference Include="..\..\..\src\Maintenance\CHG.iCLASSFW.Maintenance.Server\CHG.iCLASSFW.Maintenance.Server.csproj" />
    <ProjectReference Include="..\..\..\src\Scheduling\CHG.iCLASSFW.Scheduling.Server\CHG.iCLASSFW.Scheduling.Server.csproj" />
    <ProjectReference Include="..\..\..\src\Server\CHG.iCLASSFW.AppServer.WebApi\CHG.iCLASSFW.AppServer.WebApi.csproj" />
    <ProjectReference Include="..\..\..\src\UDM\CHG.iCLASSFW.UDM.Server\CHG.iCLASSFW.UDM.Server.csproj" />
    <ProjectReference Include="..\CHG.Demo.Managers\CHG.Demo.Managers.vbproj" />
    <ProjectReference Include="..\CHG.Demo.Server\CHG.Demo.Server.csproj" />
  </ItemGroup>
  <ItemGroup>
    <None Update="log4net.config">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="CHGCodeAnalyzers" Version="1.3.11" PrivateAssets="All" />
    <PackageReference Include="codeessentials.AspNetCore.Diagnostics.Demystifier" Version="0.1.28" />
    <PackageReference Include="codeessentials.Extensions.Logging.Demystifier" Version="0.1.28" />
    <PackageReference Include="IdentityModel.AspNetCore.OAuth2Introspection" Version="3.4.1" />
    <PackageReference Include="IdentityServer4.AccessTokenValidation" Version="2.6.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="2.1.4" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Authorization.Policy" Version="2.1.2" />
    <PackageReference Include="Microsoft.AspNetCore.Hosting.WindowsServices" Version="2.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc.Formatters.Json" Version="2.1.3" />
    <PackageReference Include="Microsoft.AspNetCore.ResponseCompression" Version="2.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="2.2.5" />
  </ItemGroup>
</Project>
bjorkstromm commented 5 years ago

Thanks! Would you mind submitting the contents of project.assets.json located on obj folder? The error seems to be related to parsing that file.

jefflafay commented 5 years ago

I'm getting the same issue and it's because there are two targets. So maybe the code needs to be updated to handle multiple targets? I'm providing a top level view of my project.assets.json because it's 24k lines and I think that the multiple targets probably highlight the issue since Single() is going to throw an exception with multiple targets. Work around in the code might be First() or FirstOrDefault() but that's just my first thought and opinion.

{ "version": 3, "targets": { ".NETCoreApp,Version=v2.2": { // ... whole lot of data! }, ".NETCoreApp,Version=v2.2/win-x64": { // ... whole lot of data! } } }

bjorkstromm commented 5 years ago

Thanks, will see if I’m able to reproduce. Multiple targets should not be sn issue, but for some reason the project.assets.json contains two targets with same TFM. Which is weird.

jefflafay commented 5 years ago

Multiple targets would always be an issue if you're calling Single() on a collection with more than one, that's why its usage is seldom. First() and FirstOrDefault() tend to be best practice unless you've already explicitly checked that there is a single element before trying to access it.

bjorkstromm commented 5 years ago

Hence the predicate inside the Single(), https://github.com/mholo65/depends/blob/master/src/Depends.Core/DependencyAnalyzer.cs#L205, and an expectation not to find more than one matching elements. In the project.assets.json files I worked with, when testing I’ve seen multiple targets, but only one target per target framework. I can’t understand why there are more than one target with same target framework, therefore it would be great to have a look at such file.

jefflafay commented 5 years ago

I'm not sure why this project does that but I do have other projects that target windows and macos but the same framework. That could be another instance.

I'll look over my file and make sure it doesn't have anything sensitive. Should I just post the file contents here or would you like me to send it to you another way? Thanks for the help!

bjorkstromm commented 5 years ago

Now I see. <OutputType>Exe</OutputType> in the .csproj will create two targets in project.assets.json for the same target framework. One with the RID (runtime identifier) and one without. Need to dig deeper and decide which one of these to pick.

jefflafay commented 5 years ago

Fantastic, let me know if you need any other info.

bjorkstromm commented 5 years ago

Fixed in https://github.com/mholo65/depends/commit/5549980c646b5e3c7e00a0d0854a0c6d333afa95, I've now pushed 0.3.1 to NuGet. Will be available soon.