{"record":{"id":"d07230b4d6391d5c","repo":"stride3d/stride","slug":"an-asset-with-the-same-id-0-is-already-registered-with-the","errorCode":null,"errorMessage":"An asset with the same id [{0}] is already registered with the location [{1}]","messagePattern":"An asset with the same id \\[(.+?)\\] is already registered with the location \\[(.+?)\\]","errorType":"validation","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/assets/Stride.Core.Assets/PackageAssetCollection.cs","lineNumber":360,"sourceCode":"        {\n            if (container.AssetNamespace is not null)\n            {\n                item.Location = location = container.Qualify(location);\n            }\n            else if (location.IsAbsolute)\n            {\n                throw new ArgumentException(\"Asset location [{0}] must be relative and not absolute (not start with '/')\".ToFormat(location), nameof(item));\n            }\n        }\n\n        if (referenceable && mapPathToId.ContainsKey(location))\n        {\n            throw new ArgumentException(\"An asset [{0}] with the same location [{1}] is already registered \".ToFormat(mapPathToId[location], location.GetDirectoryAndFileName()), nameof(item));\n        }\n\n        if (mapIdToPath.ContainsKey(item.Id))\n        {\n            throw new ArgumentException(\"An asset with the same id [{0}] is already registered with the location [{1}]\".ToFormat(item.Id, location.GetDirectoryAndFileName()), nameof(item));\n        }\n\n        if (location.HasDrive)\n        {\n            throw new ArgumentException(\"Asset location [{0}] cannot contain drive information\".ToFormat(location), nameof(item));\n        }\n\n        if (location.GetDirectory()?.StartsWith(\"..\", StringComparison.Ordinal) == true)\n        {\n            throw new ArgumentException(\"Asset location [{0}] cannot start with relative '..'\".ToFormat(location), nameof(item));\n        }\n\n        // Double check that this asset is not already stored in another package for this session\n        if (Package.Session != null)\n        {\n            foreach (var otherPackage in Package.Session.Packages)\n            {\n                if (otherPackage != Package)","sourceCodeStart":342,"sourceCodeEnd":378,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/assets/Stride.Core.Assets/PackageAssetCollection.cs#L342-L378","documentation":"The collection keeps mapIdToPath so each asset id resolves to exactly one location. CheckCanAdd throws when an asset with the same AssetId is already registered — ids must be globally unique since they are the target of asset references.","triggerScenarios":"Calling package.Assets.Add(item) with an Id that already exists in mapIdToPath — typically re-adding an asset that is already in the collection, or two assets sharing a cloned id.","commonSituations":"Adding an asset twice (e.g. retry logic that does not remove first); deep-copying assets without generating a new AssetId; loading the same asset into the collection from two sources.","solutions":["Generate a fresh id for the new asset: item.Id = AssetId.New().","If the asset already exists and you meant an update, look it up by id and update its Asset/Location instead of adding.","Remove the existing entry (package.Assets.RemoveById(id) or ContainsById check) before re-adding.","Guard with package.Assets.ContainsById(item.Id) before calling Add."],"exampleFix":"// before\nvar clone = new AssetItem(item.Location, item.Asset) { Id = item.Id }; // same id\npackage.Assets.Add(clone); // throws\n\n// after\nvar clone = new AssetItem(item.Location, item.Asset) { Id = AssetId.New() };\npackage.Assets.Add(clone);","handlingStrategy":"validation","validationCode":"if (package.Assets.ContainsById(item.Id))\n    item.Id = AssetId.New();\npackage.Assets.Add(item);","typeGuard":"bool IdIsFree(Package p, AssetId id) => !p.Assets.ContainsById(id);","tryCatchPattern":"try { package.Assets.Add(item); }\ncatch (ArgumentException e) when (e.Message.Contains(\"same id\"))\n{ item.Id = AssetId.New(); package.Assets.Add(item); }","preventionTips":["Always clone with a fresh AssetId","Never re-add an asset that is already in the collection","Use update-by-id instead of Add for existing assets"],"tags":["assets","duplicate","id","argument-exception"],"backgroundTag":"file-already-exists","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}