{"record":{"id":"98b0d61cc7f964d6","repo":"stride3d/stride","slug":"a-scene-matching-the-given-sceneid-already-exists","errorCode":null,"errorMessage":"A scene matching the given {sceneId}, already exists.","messagePattern":"A scene matching the given (.+?), already exists\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/editor/Stride.Assets.Presentation/AssetEditors/SceneEditor/Game/SceneEditorGame.cs","lineNumber":40,"sourceCode":"\n        public SceneEditorGame(TaskCompletionSource<bool> gameContentLoadedTaskSource, IEffectCompiler effectCompiler, string effectLogPath)\n            : base(gameContentLoadedTaskSource, effectCompiler, effectLogPath)\n        {\n\n        }\n\n        public event Action<Scene> SceneAdded;\n        public event Action<Scene> SceneRemoved;\n\n        /// <summary>\n        /// Adds a new scene with the provided <paramref name=\"sceneId\"/>.\n        /// </summary>\n        /// <param name=\"sceneId\">The identifier of the scene to add.</param>\n        /// <param name=\"parentId\">The identifier of an existing parent scene, or <see cref=\"Guid.Empty\"/>.</param>\n        public void AddScene(Guid sceneId, Guid parentId)\n        {\n            if (sceneId == Guid.Empty) throw new InvalidOperationException($\"{nameof(sceneId)} cannot be {nameof(Guid.Empty)}.\");\n            if (scenes.ContainsKey(sceneId)) throw new InvalidOperationException($\"A scene matching the given {sceneId}, already exists.\");\n\n            EnsureContentScene();\n\n            var scene = new Scene { Id = sceneId };\n            var parent = parentId != Guid.Empty ? GetScene(parentId) : ContentScene;\n            AddSceneToParent(scene, parent);\n            scenes.Add(sceneId, scene);\n            SceneAdded?.Invoke(scene);\n        }\n\n        /// <summary>\n        /// Moves an existing scene identified by <paramref name=\"sceneId\"/> under the parent scene identified by <paramref name=\"parentId\"/>.\n        /// </summary>\n        /// <param name=\"sceneId\">The identifier of the scene to move.</param>\n        /// <param name=\"parentId\">The identifier of an existing parent scene, or <see cref=\"Guid.Empty\"/>.</param>\n        public void MoveScene(Guid sceneId, Guid parentId)\n        {\n            if (sceneId == Guid.Empty)","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/editor/Stride.Assets.Presentation/AssetEditors/SceneEditor/Game/SceneEditorGame.cs#L22-L58","documentation":"SceneEditorGame.AddScene throws this InvalidOperationException when the scenes dictionary already contains the given sceneId. Scene ids are unique keys; adding a duplicate would corrupt the hierarchy.","triggerScenarios":"Calling AddScene twice with the same sceneId, e.g. re-running an import or re-executing a load routine without checking existence.","commonSituations":"Reloading the same asset twice; retry logic that re-invokes AddScene after a partial failure; id collision from a poor id generator.","solutions":["Check whether the scene already exists before adding (skip if present).","Remove the existing scene first if it should be replaced.","Use a fresh Guid.NewGuid() per scene.","Catch InvalidOperationException and treat the add as a no-op for duplicates."],"exampleFix":"// before\nsceneEditorGame.AddScene(sceneId, parentId); // may duplicate\n// after\nif (sceneEditorGame.GetScene(sceneId) == null)\n    sceneEditorGame.AddScene(sceneId, parentId);","handlingStrategy":"validation","validationCode":"if (game.GetScene(sceneId) != null) return; // already added","typeGuard":null,"tryCatchPattern":"try { game.AddScene(sceneId, parentId); } catch (InvalidOperationException ex) when (ex.Message.Contains(\"already exists\")) { /* idempotent: scene present */ }","preventionTips":["Make add operations idempotent by checking existence first","Use fresh Guids per scene, never reuse ids across reloads","Guard retry logic so failed adds are not re-invoked blindly"],"tags":["stride-editor","scene","duplicate-key","invalid-state-transition"],"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-16T04:17:20.429Z"}