{"record":{"id":"cba2f572e21e16fc","repo":"microsoft/aspire","slug":"assets-file-not-found-assetspath","errorCode":null,"errorMessage":"Assets file not found: {assetsPath}","messagePattern":"Assets file not found: (.+?)","errorType":"exception","errorClass":"FileNotFoundException","httpStatus":null,"severity":"error","filePath":"src/Aspire.Managed/NuGet/Commands/NuGetPackageAssetResolver.cs","lineNumber":54,"sourceCode":"\n    public required bool IsManagedAssembly { get; init; }\n\n    public required bool IsNativeLibrary { get; init; }\n\n    public string? Culture { get; init; }\n}\n\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        }","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/microsoft/aspire/blob/25830f84bd145686607ad00c057b3f84e2e51d43/src/Aspire.Managed/NuGet/Commands/NuGetPackageAssetResolver.cs#L36-L72","documentation":"NuGetPackageAssetResolver.Resolve reads a NuGet project.assets.json file to enumerate package assets. It throws FileNotFoundException when the assets file does not exist at the given path, since parsing cannot proceed without it.","triggerScenarios":"Calling Resolve(assetsPath, framework, ...) with a path where project.assets.json has not been generated — typically before `dotnet restore` has run, or pointing at the wrong project directory.","commonSituations":"Restoring a freshly cloned project without running restore, resolving assets for a deleted/cleaned obj directory, or passing a typo'd path to the resolver.","solutions":["Run `dotnet restore` (or the equivalent RestoreCommand) for the project so project.assets.json is generated in obj/.","Verify the assetsPath points to the correct obj/project.assets.json for the target project.","Check that the project directory was not cleaned (bin/obj removed) after a previous restore."],"exampleFix":"// before\nresolver.Resolve(\"obj/project.assets.json\", \"net10.0\", null);\n// after\nif (!File.Exists(\"obj/project.assets.json\")) { await restoreCommand.RunAsync(projectPath); }\nresolver.Resolve(\"obj/project.assets.json\", \"net10.0\", null);","handlingStrategy":"validation","validationCode":"if (!File.Exists(assetsPath))\n{\n    throw new InvalidOperationException($\"Run 'dotnet restore' first; assets file missing at {assetsPath}\");\n}","typeGuard":null,"tryCatchPattern":"try { resolver.Resolve(assetsPath, tfm, rid); }\ncatch (FileNotFoundException ex) { logger.LogError(ex, \"Assets file missing — run dotnet restore for the project.\"); throw; }","preventionTips":["Always run dotnet restore before resolving package assets","Resolve paths relative to the project file (Path.Combine(projectDir, \"obj\", \"project.assets.json\"))","Check for obj/ directory existence as a precondition in tooling"],"tags":["nuget","file","restore"],"backgroundTag":"file-not-found","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"}