{"record":{"id":"94bf4caa49ff9d6e","repo":"microsoft/aspire","slug":"failed-to-parse-project-assets-json","errorCode":null,"errorMessage":"Failed to parse project.assets.json","messagePattern":"Failed to parse project\\.assets\\.json","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Managed/NuGet/Commands/NuGetPackageAssetResolver.cs","lineNumber":61,"sourceCode":"\ninternal static class NuGetPackageAssetResolver\n{\n    public static NuGetPackageAssetResolution Resolve(\n        string assetsPath,\n        string framework,\n        string? runtimeIdentifier,\n        Action<string>? verboseLog = null)\n    {\n        if (!File.Exists(assetsPath))\n        {\n            throw new FileNotFoundException($\"Assets file not found: {assetsPath}\", assetsPath);\n        }\n\n        var lockFileFormat = new LockFileFormat();\n        var lockFile = lockFileFormat.Read(assetsPath);\n        if (lockFile is null)\n        {\n            throw new InvalidOperationException(\"Failed to parse project.assets.json\");\n        }\n\n        var effectiveRuntimeIdentifier = string.IsNullOrWhiteSpace(runtimeIdentifier)\n            ? RuntimeInformation.RuntimeIdentifier\n            : runtimeIdentifier;\n        var target = ResolveTarget(lockFile, framework, effectiveRuntimeIdentifier);\n        if (target is null)\n        {\n            throw new InvalidOperationException(\n                $\"Target framework '{framework}' not found in assets file. Available targets: {string.Join(\", \", lockFile.Targets.Select(t => t.TargetFramework.GetShortFolderName()))}\");\n        }\n\n        var packagesPath = GetPackagesPath(lockFile);\n        var targetFramework = target.TargetFramework.GetShortFolderName();\n        var assets = new List<NuGetPackageAsset>();\n        var skippedCount = 0;\n        var runtimeIdentifiers = GetRuntimeIdentifiers(assetsPath, framework, effectiveRuntimeIdentifier);\n        var packageLibraries = lockFile.Libraries","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Managed/NuGet/Commands/NuGetPackageAssetResolver.cs#L43-L79","documentation":"After confirming the assets file exists, Resolve parses it with NuGet's LockFileFormat. If parsing yields a null LockFile — meaning the file content is not a valid project.assets.json structure — an InvalidOperationException is thrown.","triggerScenarios":"Calling Resolve on a project.assets.json that exists but is corrupt, truncated, empty, or written by an incompatible tooling version so LockFileFormat.Read returns null.","commonSituations":"An interrupted restore leaving a partial assets file, manual edits to project.assets.json, or concurrent builds writing to the same obj directory.","solutions":["Delete the obj (and bin) directory and re-run `dotnet restore` to regenerate a valid assets file.","Verify project.assets.json is valid JSON and was produced by `dotnet restore`, not hand-edited.","Avoid concurrent restore/build operations on the same project directory."],"exampleFix":"// before\nresolver.Resolve(\"obj/project.assets.json\", \"net10.0\", null); // corrupt file\n// after\nDirectory.Delete(\"obj\", recursive: true);\nProcess.Start(\"dotnet\", \"restore\").WaitForExit();\nresolver.Resolve(\"obj/project.assets.json\", \"net10.0\", null);","handlingStrategy":"try-catch","validationCode":"try { using var doc = JsonDocument.Parse(File.ReadAllText(assetsPath)); }\ncatch (JsonException) { Directory.Delete(Path.GetDirectoryName(assetsPath)!, recursive: true); /* re-restore */ }","typeGuard":null,"tryCatchPattern":"try { resolver.Resolve(assetsPath, tfm, rid); }\ncatch (InvalidOperationException ex) when (ex.Message == \"Failed to parse project.assets.json\")\n{ RestoreProject(projectDir); resolver.Resolve(assetsPath, tfm, rid); }","preventionTips":["Avoid concurrent restores/builds on the same project directory","Never hand-edit project.assets.json","On failure, delete obj/ and re-restore rather than retrying the parse"],"tags":["nuget","parse","json"],"backgroundTag":"json-parse-error","analyzedSha":"25830f84bd145686607ad00c057b3f84e2e51d43","analyzedAt":"2026-09-16T11:10:06.193Z","contentChangedAt":"2026-09-16T11:10:06.193Z","schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}