stride3d/stride · error · ArgumentException

An asset [ ] with the same location [ ] is already…

Error message

An asset [{0}] with the same location [{1}] is already registered 

What it means

The collection maintains a mapPathToId index so each referenceable asset location is unique within a package. CheckCanAdd throws when the location being added is already registered to another asset id, preventing two referenceable assets from resolving to the same path.

Solutions

  1. Choose a unique location for the new asset (e.g. append a suffix) before adding.
  2. Remove or rename the conflicting asset first: package.Assets.Remove(existing) or change its Location.
  3. Retrieve the existing asset by location (package.Assets.Find(location)) if you actually meant to update it rather than add a duplicate.
  4. Mark the asset type non-referenceable via AssetDescriptionAttribute if duplicate locations are legitimately acceptable for it.

Example fix

// before
var item = new AssetItem(existingLocation, newAsset) { Id = AssetId.New() };
package.Assets.Add(item); // throws: location already registered

// after
if (package.Assets.Find(existingLocation) is { } existing)
    package.Assets.Remove(existing);
package.Assets.Add(new AssetItem(existingLocation, newAsset) { Id = AssetId.New() });
Defensive patterns

Strategy: validation

Validate before calling

if (package.Assets.Find(item.Location) is { } existing && referenceable)
    package.Assets.Remove(existing);
package.Assets.Add(item);

Type guard

bool LocationIsFree(Package p, UFile loc) => p.Assets.Find(loc) == null;

Try / catch

try { package.Assets.Add(item); }
catch (ArgumentException e) when (e.Message.Contains("same location"))
{ /* find/replace or rename location */ }

Prevention

When it happens

Trigger: Adding an asset whose computed location (after optional namespace qualification) equals the location of an asset already in the collection, when the new asset is referenceable (AssetDescriptionAttribute.Referenceable defaults to true). Only applies when referenceable — non-referenceable assets may share locations.

Common situations: Duplicating an asset in code and reusing the same location string; importing assets that collide with existing file names; renaming scenarios where the old entry was not removed before adding the new one; two different source files mapping to the same package-relative location.

Understand the failure class

Background: "already exists" / EEXIST / FileAlreadyExistsException: what the 'file already exists' error means and how to fix it — this error's family across 37 libraries.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/9973867f4d18985a. Report an issue: GitHub.

Appendix: source

Thrown at sources/assets/Stride.Core.Assets/PackageAssetCollection.cs:355

        // unqualified locations, qualified here like the loaders do. Plain packages stay
        // relative-only (that reservation is what makes rooted URLs collision-free).
        // Detached packages (clones, pack-time copies) have no container: locations pass through.
        var location = item.Location;
        if (Package.Container is { } container)
        {
            if (container.AssetNamespace is not null)
            {
                item.Location = location = container.Qualify(location);
            }
            else if (location.IsAbsolute)
            {
                throw new ArgumentException("Asset location [{0}] must be relative and not absolute (not start with '/')".ToFormat(location), nameof(item));
            }
        }

        if (referenceable && mapPathToId.ContainsKey(location))
        {
            throw new ArgumentException("An asset [{0}] with the same location [{1}] is already registered ".ToFormat(mapPathToId[location], location.GetDirectoryAndFileName()), nameof(item));
        }

        if (mapIdToPath.ContainsKey(item.Id))
        {
            throw new ArgumentException("An asset with the same id [{0}] is already registered with the location [{1}]".ToFormat(item.Id, location.GetDirectoryAndFileName()), nameof(item));
        }

        if (location.HasDrive)
        {
            throw new ArgumentException("Asset location [{0}] cannot contain drive information".ToFormat(location), nameof(item));
        }

        if (location.GetDirectory()?.StartsWith("..", StringComparison.Ordinal) == true)
        {
            throw new ArgumentException("Asset location [{0}] cannot start with relative '..'".ToFormat(location), nameof(item));
        }

        // Double check that this asset is not already stored in another package for this session

View on GitHub (pinned to 96fad776d2)