stride3d/stride · error · FileNotFoundException

Unable to find project

Error message

Unable to find project

What it means

AddExistingProject throws FileNotFoundException when the (absolute) project path does not exist on disk. It validates the file exists before attempting to load the package so the caller gets a clear 'Unable to find project' error.

Solutions

  1. Check File.Exists(projectPath) before calling and surface a friendly message
  2. Verify the path points at the actual .csproj file, not the directory
  3. Run any project generation/codegen step that creates the file first
  4. Fix the configured path (typo, wrong base directory)

Example fix

// before
session.AddExistingProject(@"D:\src\MyGame\MyGame.cproj", logger); // typo
// after
var path = new UFile(@"D:\src\MyGame\MyGame.csproj");
if (!File.Exists(path)) throw new FileNotFoundException($"Project not found: {path}", path);
session.AddExistingProject(path, logger);
Defensive patterns

Strategy: validation

Validate before calling

if (!File.Exists(projectPath))
    throw new FileNotFoundException($"Project file not found: {Path.GetFullPath(projectPath)}", projectPath);

Try / catch

try { session.AddExistingProject(path, logger); }
catch (FileNotFoundException ex) { logger.Error(ex, "Project file missing — check path or generate the project"); }

Prevention

When it happens

Trigger: Calling session.AddExistingProject(path, logger) with a valid absolute path where File.Exists(path) is false — wrong filename, missing extension, or project not yet generated.

Common situations: Typos in the project file name, pointing at the folder instead of the .csproj, project deleted or not yet restored/generated (e.g. codegen step not run), path casing/drive issues.

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 stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/0b6195c85a60ffde. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/PackageSession.cs:702

            }
        }
    }

    /// <summary>
    /// Adds an existing package to the current session.
    /// </summary>
    /// <param name="projectPath">The project or package path.</param>
    /// <param name="logger">The session result.</param>
    /// <param name="loadParametersArg">The load parameters argument.</param>
    /// <exception cref="ArgumentNullException">packagePath</exception>
    /// <exception cref="ArgumentException">Invalid relative path. Expecting an absolute package path;packagePath</exception>
    /// <exception cref="FileNotFoundException">Unable to find package</exception>
    public PackageContainer AddExistingProject(UFile projectPath, ILogger logger, PackageLoadParameters? loadParametersArg = null)
    {
        ArgumentNullException.ThrowIfNull(projectPath);
        ArgumentNullException.ThrowIfNull(logger);
        if (!projectPath.IsAbsolute) throw new ArgumentException("Invalid relative path. Expecting an absolute project path", nameof(projectPath));
        if (!File.Exists(projectPath)) throw new FileNotFoundException("Unable to find project", projectPath);

        var loadParameters = loadParametersArg ?? PackageLoadParameters.Default();

        Package package;
        PackageContainer project;
        try
        {
            // Enable reference analysis caching during loading
            AssetReferenceAnalysis.EnableCaching = true;

            project = LoadProject(logger, projectPath.ToOSPath(), loadParametersArg);
            Projects.Add(project);

            package = project.Package;

            // Load all missing references/dependencies
            LoadMissingDependencies(logger, loadParameters);

View on GitHub (pinned to 96fad776d2)