{"record":{"id":"b688f62a8a49b216","repo":"stride3d/stride","slug":"assets-must-have-the-same-id","errorCode":null,"errorMessage":"Assets must have the same Id.","messagePattern":"Assets must have the same Id\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs","lineNumber":519,"sourceCode":"            if (newName == name)\n                return;\n\n            using (var transaction = UndoRedoService.CreateTransaction())\n            {\n                string previousName = name;\n                UpdateUrl(package, directory, newName);\n                UndoRedoService.SetName(transaction, $\"Rename asset '{previousName}' to '{newName}'\");\n            }\n        }\n\n        /// <summary>\n        /// Replace the internal asset with the one provided, this function expects the two assets to have the same identity \n        /// </summary>\n        /// <exception cref=\"ArgumentException\">The asset provided does not have the same identity as the current one</exception>\n        public void UpdateAsset(Asset newAsset, ILogger loggerResult)\n        {\n            if (newAsset.Id != AssetItem.Asset.Id)\n                throw new ArgumentException(\"Assets must have the same Id.\");\n\n            if (newAsset.MainSource != AssetItem.Asset.MainSource)\n                throw new ArgumentException(\"Assets must have the same source.\");\n\n            var newAssetItem = AssetItem.Clone(newAsset: newAsset);\n\n            package.Assets.Remove(AssetItem);\n            package.Assets.Add(newAssetItem);\n\n            AssetItem = newAssetItem;\n\n            PropertyGraph?.Dispose();\n            Session.GraphContainer.UnregisterGraph(assetItem.Id);\n\n            PropertyGraph = Session.GraphContainer.InitializeAsset(assetItem, loggerResult);\n            if (PropertyGraph != null)\n            {\n                PropertyGraph.BaseContentChanged += BaseContentChanged;","sourceCodeStart":501,"sourceCodeEnd":537,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs#L501-L537","documentation":"AssetViewModel.UpdateAsset replaces the internal asset with a new one and requires the replacement to be the same identity — i.e. share the same Id — because it is an in-place update of an existing asset item, not a replacement with a different asset. A mismatched Id is a caller error, raised as ArgumentException.","triggerScenarios":"Calling UpdateAsset(newAsset, logger) with an Asset whose Id differs from AssetItem.Asset.Id, e.g. deserializing a copy/duplicate of the asset instead of the updated version of the same asset.","commonSituations":"Reload/reimport workflows where the file was duplicated (getting a new Guid) instead of saved in place; loading an older file version with a different Id; mixing assets between packages.","solutions":["Ensure the new asset was loaded from the same asset item so its Id matches; do not pass clones or duplicates.","If Ids legitimately differ, remove/re-add the asset instead of calling UpdateAsset.","Re-import or re-save the source file so it keeps the original asset Id."],"exampleFix":"// before\nif (loadedAsset.Id != currentAsset.Id) { /* silently update */ }\nvm.UpdateAsset(loadedAsset, logger);\n// after\nif (loadedAsset.Id != vm.AssetItem.Asset.Id)\n    throw new InvalidOperationException(\"Reloaded asset is a copy, not the same asset.\");\nvm.UpdateAsset(loadedAsset, logger);","handlingStrategy":"validation","validationCode":"if (newAsset.Id != vm.AssetItem.Asset.Id) { logger.Error(\"Cannot update: asset Ids differ (copy vs original)\"); return; }","typeGuard":"bool IsSameAssetIdentity(AssetViewModel vm, Asset a) => a.Id == vm.AssetItem.Asset.Id;","tryCatchPattern":"try { vm.UpdateAsset(newAsset, logger); }\ncatch (ArgumentException ex) { logger.Error(ex, \"Reloaded asset has a different Id; it is not an update of this asset\"); }","preventionTips":["Save updates in place so the asset keeps its Guid","Detect duplicated asset files before loading them","For legitimately different assets use remove/add, not UpdateAsset"],"tags":["assets","identity","id-mismatch","argument-validation"],"backgroundTag":"invalid-argument-value","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"}