{"record":{"id":"2719edc2e6345317","repo":"stride3d/stride","slug":"assets-must-have-the-same-source","errorCode":null,"errorMessage":"Assets must have the same source.","messagePattern":"Assets must have the same source\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs","lineNumber":522,"sourceCode":"            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;\n                PropertyGraph.Changed += AssetPropertyChanged;\n                PropertyGraph.ItemChanged += AssetPropertyChanged;\n                PropertyGraph.Initialize();","sourceCodeStart":504,"sourceCodeEnd":540,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Core.Assets.Editor/ViewModel/AssetViewModel.cs#L504-L540","documentation":"In the same UpdateAsset flow, the editor also requires the new asset's MainSource to equal the current asset's MainSource. The update path only refreshes the asset in place and cannot swap its primary source; a different source means the caller is handing in an asset that is not really an updated version of this one, so an ArgumentException is thrown.","triggerScenarios":"Calling UpdateAsset with an asset whose MainSource differs from the current asset's — e.g. reloading a file whose source reference changed, or passing an entirely different asset type/file.","commonSituations":"Re-importing an asset after its source file was relocated or repointed; template/archetype reloads that rebuilt the asset with different source settings; hand-crafted Asset objects in tooling.","solutions":["Reload the asset preserving its original MainSource; only content/properties should differ.","If the source must change, delete the asset and create a new one rather than using UpdateAsset.","Log/compare newAsset.MainSource vs AssetItem.Asset.MainSource before calling to detect the divergence early."],"exampleFix":"// before\nvm.UpdateAsset(reloadedAsset, logger); // reloadedAsset.MainSource changed\n// after\nif (reloadedAsset.MainSource != vm.AssetItem.Asset.MainSource)\n{\n    logger.Error(\"Asset source changed; recreate the asset instead of updating.\");\n    return;\n}\nvm.UpdateAsset(reloadedAsset, logger);","handlingStrategy":"validation","validationCode":"if (newAsset.MainSource != vm.AssetItem.Asset.MainSource) { logger.Error(\"Cannot update: asset MainSource changed; recreate the asset\"); return; }","typeGuard":"bool IsUpdateCompatible(AssetViewModel vm, Asset a) => a.Id == vm.AssetItem.Asset.Id && a.MainSource == vm.AssetItem.Asset.MainSource;","tryCatchPattern":"try { vm.UpdateAsset(newAsset, logger); }\ncatch (ArgumentException ex) { logger.Error(ex, \"Asset MainSource mismatch; delete and recreate instead\"); }","preventionTips":["Never repoint an asset's source file and then attempt an in-place reload","Verify MainSource equality in re-import pipelines before calling UpdateAsset","Treat source changes as create-new-asset workflows"],"tags":["assets","source-mismatch","update","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"}