{"record":{"id":"22b25d7fc2fbc11a","repo":"babalae/better-genshin-impact","slug":"windows-sid-22b25d","errorCode":null,"errorMessage":"无法取得当前 Windows 用户 SID。","messagePattern":"无法取得当前 Windows 用户 SID。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Instance/InstanceContext.cs","lineNumber":79,"sourceCode":"{\n    public BetterGiInstanceType InstanceType { get; init; }\n\n    public int ProcessId { get; init; }\n\n    public int WindowsSessionId { get; init; }\n\n    public DateTimeOffset StartedAt { get; init; }\n}\n\ninternal static class InstancePipeNames\n{\n    private const string Prefix = \"BetterGI.v2.user-\";\n\n    internal static string ForCurrentUser()\n    {\n        using var identity = WindowsIdentity.GetCurrent();\n        var userSid = identity.User\n                      ?? throw new InvalidOperationException(\"无法取得当前 Windows 用户 SID。\");\n        return ForUserSid(userSid.Value);\n    }\n\n    internal static string ForUserSid(string userSid)\n    {\n        return $\"{Prefix}{userSid}.root\";\n    }\n}\n","sourceCodeStart":61,"sourceCodeEnd":88,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceContext.cs#L61-L88","documentation":"Thrown by InstancePipeNames.ForCurrentUser when WindowsIdentity.GetCurrent().User is null — the per-user pipe name is derived from the user SID, so without one the name cannot be constructed. This runs early, during InstanceBootstrap.Initialize, before any pipe is created.","triggerScenarios":"Same as 471: the process runs under an account with no user SID. ForCurrentUser() is called at bootstrap to compute the root pipe name for the current user.","commonSituations":"BetterGI launched from a service/automation account lacking a user SID; sandboxed or virtualized Windows where the identity has no user SID.","solutions":["Run BetterGI as a normal interactive Windows user account that has a user SID.","Confirm via `whoami /user` that the account exposes a user SID.","Avoid launching BetterGI from contexts that strip the user token (e.g. some task scheduler service accounts)."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"using var identity = WindowsIdentity.GetCurrent();\nvar userSid = identity.User ?? throw new InvalidOperationException(\"无法取得当前 Windows 用户 SID。\");\nvar pipeName = InstancePipeNames.ForUserSid(userSid.Value);","typeGuard":null,"tryCatchPattern":"try\n{\n    var rootPipeName = InstancePipeNames.ForCurrentUser();\n}\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"SID\"))\n{\n    logger.LogCritical(ex, \"No user SID at bootstrap; use an interactive Windows account\");\n}","preventionTips":["Run BetterGI as an interactive Windows user with a valid SID.","Confirm the account exposes a user SID via `whoami /user`.","Do not launch BetterGI from service contexts that strip the user token."],"tags":["windows","identity","security","environment","named-pipe"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}