{"record":{"id":"c7a1559783eeb323","repo":"cefsharp/CefSharp","slug":"generated-messageid-0-doesn-t-match-returned-mes","errorCode":null,"errorMessage":"Generated MessageId {0} doesn't match returned Message Id {1}","messagePattern":"Generated MessageId (.+?) doesn't match returned Message Id (.+?)","errorType":"exception","errorClass":"DevToolsClientException","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/DevTools/DevToolsClient.cs","lineNumber":193,"sourceCode":"                throw new DevToolsClientException(\"Unable to invoke ExecuteDevToolsMethod on CEF UI Thread.\");\n            }\n\n            return taskCompletionSource.Task;\n        }\n\n        private void ExecuteDevToolsMethod(IBrowserHost browserHost, int messageId, string method, IDictionary<string, object> parameters, DevToolsMethodResponseContext methodResultContext)\n        {\n            try\n            {\n                var returnedMessageId = browserHost.ExecuteDevToolsMethod(messageId, method, parameters);\n                if (returnedMessageId == 0)\n                {\n                    throw new DevToolsClientException(string.Format(\"Failed to execute dev tools method {0}.\", method));\n                }\n                else if (returnedMessageId != messageId)\n                {\n                    //For some reason our message Id's don't match\n                    throw new DevToolsClientException(string.Format(\"Generated MessageId {0} doesn't match returned Message Id {1}\", returnedMessageId, messageId));\n                }\n            }\n            catch (Exception ex)\n            {\n                queuedCommandResults.TryRemove(messageId, out _);\n                methodResultContext.SetException(ex);\n            }\n        }\n\n        /// <inheritdoc/>\n        public void Dispose()\n        {\n            //Dispose can be called from different Threads\n            //CEF maintains a reference and the user\n            //maintains a reference, we in a rare case\n            //we end up disposing of #3725 twice from different\n            //threads. This will ensure our dispose only runs once.\n            if (Interlocked.Increment(ref disposeCount) == 1)","sourceCodeStart":175,"sourceCodeEnd":211,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/DevTools/DevToolsClient.cs#L175-L211","documentation":"Defensive check inside ExecuteDevToolsMethod: after calling IBrowserHost.ExecuteDevToolsMethod(messageId, ...) the returned id must equal the messageId passed in. A mismatch would mean CEF allocated or returned a different correlation id than requested, which would break the async result routing in queuedCommandResults. In correct builds this never happens; like the TryAdd guard it flags a native contract violation.","triggerScenarios":"A CEF/Chromium build that does not echo the caller-supplied message id; a bug in the CefSharp native interop layer; using a mismatched CefSharp.Core.Runtime (native) binary against a managed assembly of a different version. The exception is delivered asynchronously to the awaiter via SetException.","commonSituations":"Mixing CefSharp NuGet package versions across a solution (e.g. CefSharp.Common at one version but a stale CefSharp.Core.Runtime.dll in the output); building native bits from a different CEF branch than the managed wrapper; a genuine native regression in a specific CEF release.","solutions":["Ensure all CefSharp packages (CefSharp.Common, CefSharp.Core, CefSharp.Wpf/WinForms/OffScreen, CefSharp.Core.Runtime) are pinned to the exact same version - clear bin/obj and restore.","Update to the latest patch release of your CefSharp line in case the id-handling bug was fixed.","If reproducible after version alignment, capture the CEF version (Cef.CefVersion) and file a CefSharp issue with a minimal repro.","Treat the faulted Task defensively in the caller (log + retry/fallback) while the underlying issue is investigated."],"exampleFix":"// No caller-side data fix - it is an internal contract check. Caller can only react:\ntry\n{\n    await client.Page.NavigateAsync(url);\n}\ncatch (DevToolsClientException ex) when (ex.Message.Contains(\"doesn't match returned Message Id\"))\n{\n    logger.Error(ex, \"CefSharp native/managed version mismatch detected - re-pin package versions.\");\n    throw;\n}","handlingStrategy":"try-catch","validationCode":"// No caller precondition; verify package version alignment as the preventive check.\nSystem.Diagnostics.Debug.Assert(typeof(CefSharp.Cef).Assembly.GetName().Version == typeof(CefSharp.Core.RequestContext).Assembly.GetName().Version, \"CefSharp version mismatch\");","typeGuard":null,"tryCatchPattern":"try { await client.Page.NavigateAsync(url); }\ncatch (DevToolsClientException ex) when (ex.Message.Contains(\"doesn't match returned Message Id\"))\n{ logger.Fatal(ex, \"CefSharp native/managed version mismatch - re-pin packages.\"); throw; }","preventionTips":["Pin all CefSharp packages (Common, Core, Core.Runtime, Wpf/WinForms/OffScreen) to the exact same version","Clear bin/obj after upgrading to remove stale native DLLs","Log Cef.CefVersion at startup to correlate native/managed versions in bug reports"],"tags":["csharp","cefsharp","devtools","internal-invariant","version-mismatch"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}