{"record":{"id":"d545c9336232520b","repo":"babalae/better-genshin-impact","slug":"error-d545c9","errorCode":null,"errorMessage":"当前没有可用的桌面分身，请先启动桌面分身。","messagePattern":"当前没有可用的桌面分身，请先启动桌面分身。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/ChildSession/ChildSessionService.cs","lineNumber":527,"sourceCode":"            RefreshState(isAutomatic\n                ? \"桌面分身已加载，正在自动以管理员权限启动 BetterGI\"\n                : \"正在以管理员权限启动 BetterGI\");\n            await ChildSessionProcessLauncher.LaunchBetterGiAsync(childSessionId);\n            RefreshState(\n                $\"已在桌面分身（会话 {childSessionId}）中以管理员权限启动 BetterGI\");\n        }\n        finally\n        {\n            _launchSemaphore.Release();\n        }\n    }\n\n    private uint GetRequiredChildSessionId()\n    {\n        var childSessionId = ChildSessionNativeMethods.TryGetChildSessionId();\n        if (childSessionId is null)\n        {\n            throw new InvalidOperationException(\"当前没有可用的桌面分身，请先启动桌面分身。\");\n        }\n\n        return childSessionId.Value;\n    }\n\n    private void EnsureChildSessionsEnabled()\n    {\n        if (!ChildSessionNativeMethods.IsChildSessionsEnabled())\n        {\n            ChildSessionNativeMethods.EnableChildSessions();\n        }\n    }\n\n    private void OnDesktopWindowVisibilityChanged(object sender, DependencyPropertyChangedEventArgs e)\n    {\n        RefreshState();\n    }\n","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/ChildSession/ChildSessionService.cs#L509-L545","documentation":"Thrown by ChildSessionService.GetRequiredChildSessionId when ChildSessionNativeMethods.TryGetChildSessionId() returns null — no Windows Child Session (desktop clone) is currently active, so there is no target session ID to launch a process into.","triggerScenarios":"Calling LaunchBetterGiAsync() or LaunchExecutableAsync() before the RDP Child Session connection has been established and logged in. The Child Session only gets a session ID after Windows assigns one during the RDP logon sequence.","commonSituations":"User clicks \"launch program into Child Session\" before clicking \"start desktop clone\"; the Child Session was logged off or terminated out-of-band; the RDP connection is still in the connecting state (ConnectedState != 1).","solutions":["Call StartAsync() first and wait for the Child Session to reach ConnectedState == 1 (logged in).","Ensure Child Sessions are enabled on the OS (EnsureChildSessionsEnabled runs automatically during StartAsync).","If the session was logged off, restart it before launching programs into it."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Ensure a Child Session is active before launching into it.\nif (ChildSessionNativeMethods.TryGetChildSessionId() is null)\n{\n    throw new InvalidOperationException(\"当前没有可用的桌面分身，请先启动桌面分身。\");\n}","typeGuard":null,"tryCatchPattern":"try\n{\n    await childSessionService.LaunchExecutableAsync(exePath);\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"桌面分身\"))\n{\n    logger.LogError(ex, \"No active Child Session; start one first\");\n}","preventionTips":["Call StartAsync() and wait for ConnectedState == 1 before exposing launch-into-session actions.","Disable the launch button in the UI until a Child Session ID is present.","Handle the case where the session was logged off out-of-band by re-checking before each launch."],"tags":["child-session","state","validation","rdp"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}