microsoft/aspire · error · FileNotFoundException

Assets file not found

Error message

Assets file not found: {assetsPath}

What it means

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.

Solutions

  1. Run `dotnet restore` (or the equivalent RestoreCommand) for the project so project.assets.json is generated in obj/.
  2. Verify the assetsPath points to the correct obj/project.assets.json for the target project.
  3. Check that the project directory was not cleaned (bin/obj removed) after a previous restore.

Example fix

// before
resolver.Resolve("obj/project.assets.json", "net10.0", null);
// after
if (!File.Exists("obj/project.assets.json")) { await restoreCommand.RunAsync(projectPath); }
resolver.Resolve("obj/project.assets.json", "net10.0", null);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(assetsPath))
{
    throw new InvalidOperationException($"Run 'dotnet restore' first; assets file missing at {assetsPath}");
}

Try / catch

try { resolver.Resolve(assetsPath, tfm, rid); }
catch (FileNotFoundException ex) { logger.LogError(ex, "Assets file missing — run dotnet restore for the project."); throw; }

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


AI-assisted analysis of microsoft/aspire@25830f84bd (2026-09-16). Data as JSON: /api/errors/cba2f572e21e16fc. Report an issue: GitHub.

Appendix: source

Thrown at src/Aspire.Managed/NuGet/Commands/NuGetPackageAssetResolver.cs:54

    public required bool IsManagedAssembly { get; init; }

    public required bool IsNativeLibrary { get; init; }

    public string? Culture { get; init; }
}

internal static class NuGetPackageAssetResolver
{
    public static NuGetPackageAssetResolution Resolve(
        string assetsPath,
        string framework,
        string? runtimeIdentifier,
        Action<string>? verboseLog = null)
    {
        if (!File.Exists(assetsPath))
        {
            throw new FileNotFoundException($"Assets file not found: {assetsPath}", assetsPath);
        }

        var lockFileFormat = new LockFileFormat();
        var lockFile = lockFileFormat.Read(assetsPath);
        if (lockFile is null)
        {
            throw new InvalidOperationException("Failed to parse project.assets.json");
        }

        var effectiveRuntimeIdentifier = string.IsNullOrWhiteSpace(runtimeIdentifier)
            ? RuntimeInformation.RuntimeIdentifier
            : runtimeIdentifier;
        var target = ResolveTarget(lockFile, framework, effectiveRuntimeIdentifier);
        if (target is null)
        {
            throw new InvalidOperationException(
                $"Target framework '{framework}' not found in assets file. Available targets: {string.Join(", ", lockFile.Targets.Select(t => t.TargetFramework.GetShortFolderName()))}");
        }

View on GitHub (pinned to 25830f84bd)