stride3d/stride · error · InvalidOperationException
Could not find project associated to asset [{AssetItem}]
Error message
Could not find project associated to asset [{AssetItem}] What it means
ScriptSourceFileAssetViewModel.TrackDocument resolves the Roslyn Project for the asset's owning package so it can wait for the project to load (bounded retry loop). The container of the asset's package is cast to SolutionProject and its FullPath converted to an OS path; if that path is null the asset is not associated with any project in the solution, and an InvalidOperationException with the asset name is thrown.
Solutions
- Ensure the asset lives in a package that is part of the currently loaded solution with a valid .csproj FullPath.
- Reload the solution/game studio session so package containers are correctly bound to SolutionProject instances.
- Check ((SolutionProject)AssetItem.Package.Container).FullPath before calling TrackDocument and skip or queue tracking when it is null.
Example fix
// before
var sourceProject = ((SolutionProject)AssetItem.Package.Container).FullPath.ToOSPath();
// after
var container = AssetItem.Package.Container as SolutionProject;
if (container?.FullPath == null)
return; // asset not associated with a solution project; skip document tracking
var sourceProject = container.FullPath.ToOSPath(); Defensive patterns
Strategy: validation
Validate before calling
var container = AssetItem.Package.Container as SolutionProject;
if (container?.FullPath == null)
{
// asset not tied to a solution project — do not call TrackDocument
return;
} Type guard
static bool HasSolutionProject(AssetItem item) =>
item?.Package?.Container is SolutionProject p && !string.IsNullOrEmpty(p.FullPath); Try / catch
try
{
await viewModel.TrackDocument();
}
catch (InvalidOperationException ex) when (ex.Message.Contains("Could not find project associated to asset"))
{
logger.Warning($"Skipping document tracking: {ex.Message}");
} Prevention
- Only create script-source assets inside packages that belong to a loaded solution.
- Verify the solution fully loaded before initializing script asset view models.
- Null-check Package.Container as SolutionProject and FullPath before tracking.
- Reload the solution if packages were loaded standalone or a load partially failed.
When it happens
Trigger: TrackDocument (called from Initialize and UpdateIsDeletedStatus) runs on an asset whose AssetItem.Package.Container is not a project with a valid FullPath — e.g. the package is a standalone/session package not referenced by any .csproj in the current solution.
Common situations: Opening a script-source asset whose parent package was loaded outside a solution, a solution that failed to load or was partially loaded, or an asset moved to a package without an associated project file.
Understand the failure class
Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.
Related errors
- NotSupportedException
- ArgumentOutOfRangeException
- InvalidOperationException
- [{nameof(Session)}] cannot be null in {GetType().Name}
- [{nameof(Description)}.{nameof(Description.Scope)}] must be
AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14).
Data as JSON: /api/errors/658936755d6f31a1.
Report an issue: GitHub.
Appendix: source
Thrown at sources/editor/Stride.Assets.Presentation/ViewModel/ScriptSourceFileAssetViewModel.cs:257
private void TrackDocument()
{
// Make sure the path is correct
AssetItem.UpdateSourceFolders();
// Capture full path before going in a Task (might be renamed in between)
var fullPath = AssetItem.FullPath.ToOSPath();
DocumentId = Task.Run(async () =>
{
// Find DocumentId
var strideAssets = await StrideAssetsViewModel.InstanceTask;
workspace = await strideAssets.Code.Workspace;
AssetItem.UpdateSourceFolders();
var sourceProject = ((SolutionProject)AssetItem.Package.Container).FullPath.ToOSPath();
if (sourceProject == null)
throw new InvalidOperationException($"Could not find project associated to asset [{AssetItem}]");
// Wait for project to be loaded, but bounded: a project that never appears (e.g. one that
// isn't in the workspace) must not spin forever and freeze callers that block on DocumentId.
Project project = null;
for (var retries = 0; retries < 500; retries++)
{
cancellationToken.Token.ThrowIfCancellationRequested();
// Wait for project to be available (case-insensitive: MSBuild and SolutionProject paths may differ in casing)
project = workspace.CurrentSolution.Projects.FirstOrDefault(x => string.Equals(x.FilePath, sourceProject, StringComparison.OrdinalIgnoreCase));
if (project != null)
break;
await Task.Delay(10);
}
if (project == null)
{
// Couldn't locate the project; leave the asset untracked rather than hang.View on GitHub (pinned to 96fad776d2)