{"record":{"id":"a43333e533ff3e15","repo":"babalae/better-genshin-impact","slug":"openresponse-assignedtype","errorCode":null,"errorMessage":"根实例分配了不匹配的客户端类型：{openResponse.AssignedType}。","messagePattern":"根实例分配了不匹配的客户端类型：(.+?)。","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"BetterGenshinImpact/Service/Instance/InstanceService.cs","lineNumber":443,"sourceCode":"                        },\n                        RequestTimeout,\n                        cancellationToken).ConfigureAwait(false);\n                    EnsureSuccessfulResponse(openResult);\n                    openResponse =\n                        openResult.Data?.ToObject<ConnectionOpenResponse>(\n                            InstanceIpcProtocol.Serializer)\n                        ?? throw new InvalidDataException(\"根实例连接响应缺少数据。\");\n                }\n\n                if (openResponse.Disposition\n                    == ConnectionOpenDisposition.ActivationForwarded)\n                {\n                    RequestApplicationShutdown();\n                    return;\n                }\n                if (openResponse.AssignedType != Context.InstanceType)\n                {\n                    throw new InvalidOperationException(\n                        $\"根实例分配了不匹配的客户端类型：{openResponse.AssignedType}。\");\n                }\n\n                Context.SetRootSessionId(openResponse.RootSessionId);\n                connection.RemoteEndpoint = new InstanceEndpoint\n                {\n                    InstanceType = BetterGiInstanceType.Primary,\n                    ProcessId = openResponse.RootProcessId,\n                    WindowsSessionId = openResponse.RootSessionId,\n                    StartedAt = DateTimeOffset.UtcNow\n                };\n                if (!connection.IsStarted)\n                {\n                    connection.Start(cancellationToken);\n                }\n                if (connection.Completion.IsCompleted)\n                {\n                    throw new IOException(\"根实例连接在完成登记前已经关闭。\");","sourceCodeStart":425,"sourceCodeEnd":461,"githubUrl":"https://github.com/babalae/better-genshin-impact/blob/a7cb36712dcb409be610257d877fcea3597e9d6b/BetterGenshinImpact/Service/Instance/InstanceService.cs#L425-L461","documentation":"Thrown in RootConnectionLoopAsync when the connection.open response's AssignedType field does not match the child's requested Context.InstanceType. The root has authority to assign instance types — but in normal operation it should echo back the requested type (or ActivationForwarded). A mismatch means the root decided this process should play a different role than it was launched as.","triggerScenarios":"The child sent ConnectionOpenRequest.RequestedType = Context.InstanceType (e.g., ChildSession), but the root's response has AssignedType set to a different value (e.g., Primary or WebView). Looking at HandleConnectionOpenAsync, the root always echoes the requested type for Accepted connections, so a mismatch indicates either a version skew in the response model or an unexpected root-side code path.","commonSituations":"Protocol version mismatch where ConnectionOpenResponse fields are misaligned during deserialization (AssignedType reads garbage); the root instance has a bug in CreateOpenResponse that assigns the wrong type; a race where the root's context changed between receiving and responding; test fixtures that construct responses with mismatched types.","solutions":["Verify both processes run the same application version to eliminate schema deserialization skew.","Check HandleConnectionOpenAsync and CreateOpenResponse on the root side to confirm AssignedType always matches the request's RequestedType for Accepted dispositions.","Log openResponse.AssignedType and Context.InstanceType values at the throw site to identify which type was unexpectedly assigned.","If this occurs after a protocol change, ensure ConnectionOpenResponse.AssignedType maps correctly to the BetterGiInstanceType enum."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Already handled in RootConnectionLoopAsync:\ncatch (Exception exception) when (exception is InvalidOperationException or InvalidDataException)\n{\n    _logger.LogError(exception, \"连接协议错误，停止重连：{PipeName}\", Context.RootPipeName);\n    RequestApplicationShutdown();\n    return;\n}","preventionTips":["Ensure root and child run the same version so AssignedType semantics match.","Verify HandleConnectionOpenAsync assigns the correct type in CreateOpenResponse.","Log AssignedType vs requested type to diagnose mismatches."],"tags":["ipc","connection-handshake","instance-type","version-mismatch","root-connection"],"backgroundTag":null,"analyzedSha":"a7cb36712dcb409be610257d877fcea3597e9d6b","analyzedAt":"2026-08-13T16:44:57.548Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}