Skip to content

KeyNotFoundException for project with no dependencies #2

@Aldaviva

Description

@Aldaviva

Environment

  • .NET SDK 9.0.102
  • DependencyHierarchy 1.0.0
  • NuGet 6.12.3 (from Visual Studio 17.12.4)
  • .NET 8 console project with no dependencies (aside from the implicit dependency on Microsoft.NETCore.App 8.0.12 and its analyzers)

Project file

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFramework>net8.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
        <IsPackable>false</IsPackable>
        <RollForward>latestMajor</RollForward>
    </PropertyGroup>
</Project>

Error

Unhandled exception. System.Collections.Generic.KeyNotFoundException: The given key was not present in the dictionary.
   at System.Text.Json.JsonElement.GetProperty(String propertyName)
   at DependencyHierarchy.Program.<>c.<parseDependencies>b__21_2(JsonProperty framework) in /_/DependencyHierarchy/Program.cs:line 71
   at System.Linq.Enumerable.SelectManySingleSelectorIterator`2.MoveNext()
   at System.Collections.Generic.HashSet`1.UnionWith(IEnumerable`1 other)
   at System.Collections.Generic.HashSet`1..ctor(IEnumerable`1 collection, IEqualityComparer`1 comparer)
   at System.Linq.Enumerable.ToHashSet[TSource](IEnumerable`1 source, IEqualityComparer`1 comparer)
   at DependencyHierarchy.Program.parseDependencies() in /_/DependencyHierarchy/Program.cs:line 70
   at DependencyHierarchy.Program.Main() in /_/DependencyHierarchy/Program.cs:line 35
   at DependencyHierarchy.Program.<Main>()

obj\project.assets.json

{
  "version": 3,
  "targets": {
    "net8.0": {}
  },
  "libraries": {},
  "projectFileDependencyGroups": {
    "net8.0": []
  },
  "packageFolders": {
    "C:\\Users\\Ben\\.nuget\\packages\\": {}
  },
  "project": {
    "version": "1.0.0",
    "restore": {
      "projectUniqueName": "C:\\Users\\Ben\\Documents\\Projects\\UnionTypes\\Generator\\Generator.csproj",
      "projectName": "Generator",
      "projectPath": "C:\\Users\\Ben\\Documents\\Projects\\UnionTypes\\Generator\\Generator.csproj",
      "packagesPath": "C:\\Users\\Ben\\.nuget\\packages\\",
      "outputPath": "C:\\Users\\Ben\\Documents\\Projects\\UnionTypes\\Generator\\obj\\",
      "projectStyle": "PackageReference",
      "configFilePaths": [
        "C:\\Users\\Ben\\AppData\\Roaming\\NuGet\\NuGet.Config",
        "C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
      ],
      "originalTargetFrameworks": [
        "net8.0"
      ],
      "sources": {
        "C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
        "https://api.nuget.org/v3/index.json": {}
      },
      "frameworks": {
        "net8.0": {
          "targetAlias": "net8.0",
          "projectReferences": {}
        }
      },
      "warningProperties": {
        "warnAsError": [
          "NU1605"
        ]
      },
      "restoreAuditProperties": {
        "enableAudit": "true",
        "auditLevel": "low",
        "auditMode": "direct"
      },
      "SdkAnalysisLevel": "9.0.100"
    },
    "frameworks": {
      "net8.0": {
        "targetAlias": "net8.0",
        "imports": [
          "net461",
          "net462",
          "net47",
          "net471",
          "net472",
          "net48",
          "net481"
        ],
        "assetTargetFallback": true,
        "warn": true,
        "frameworkReferences": {
          "Microsoft.NETCore.App": {
            "privateAssets": "all"
          }
        },
        "runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\9.0.102/PortableRuntimeIdentifierGraph.json"
      }
    }
  }
}

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions