{"record":{"id":"b1e40896de122ade","repo":"cefsharp/CefSharp","slug":"a-call-to-withcachepath-has-already-been-made-it","errorCode":null,"errorMessage":"A call to WithCachePath has already been made, it's not possible to share settings with another RequestContext.","messagePattern":"A call to WithCachePath has already been made, it's not possible to share settings with another RequestContext\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/RequestContextBuilder.cs","lineNumber":33,"sourceCode":"    public class RequestContextBuilder\n    {\n        private RequestContextSettings _settings;\n        private IRequestContext _otherContext;\n        private RequestContextHandler _handler;\n\n        void ThrowExceptionIfContextAlreadySet()\n        {\n            if (_otherContext != null)\n            {\n                throw new Exception(\"A call to WithSharedSettings has already been made, it is no possible to provide custom settings.\");\n            }\n        }\n\n        void ThrowExceptionIfCustomSettingSpecified()\n        {\n            if (_settings != null)\n            {\n                throw new Exception(\"A call to WithCachePath has already been made, it's not possible to share settings with another RequestContext.\");\n            }\n        }\n        /// <summary>\n        /// Create the actual RequestContext instance\n        /// </summary>\n        /// <returns>Returns a new RequestContext instance.</returns>\n        public IRequestContext Create()\n        {\n            if (_otherContext != null)\n            {\n                return new CefSharp.Core.RequestContext(_otherContext, _handler);\n            }\n\n            if (_settings != null)\n            {\n                return new CefSharp.Core.RequestContext(_settings.settings, _handler);\n            }\n","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/RequestContextBuilder.cs#L15-L51","documentation":"The mirror of error 16: RequestContextBuilder.ThrowExceptionIfCustomSettingSpecified throws when you call WithSharedSettings after WithCachePath (or any method that populated _settings) has already been used. You cannot share another context's storage once custom settings are in play. Thrown as a plain System.Exception with parameter-free message.","triggerScenarios":"Chaining .WithCachePath(...).WithSharedSettings(parent); calling WithSharedSettings twice after a custom setting was added; merging a shared and a custom configuration in one builder.","commonSituations":"Builder reused across requests accumulating both kinds of calls; template builder that includes cache path, then a caller tries to share; refactor joining two configurations.","solutions":["Use a fresh builder for each distinct strategy (share vs customise).","If you previously set WithCachePath, do not call WithSharedSettings on the same builder - share instead at browser creation.","Reset builder state or use a factory that returns the correct pre-configured builder per strategy.","Add an integration test covering both code paths to catch the contradictory ordering early."],"exampleFix":"// before - throws\nvar ctx = RequestContext.Configure()\n    .WithCachePath(@\"C:\\cache\")\n    .WithSharedSettings(parent) // throws\n    .Create();\n\n// after - one strategy per builder\nvar custom = RequestContext.Configure().WithCachePath(@\"C:\\cache\").Create();","handlingStrategy":"validation","validationCode":"// Decide share-vs-customise before configuring the builder.\nRequestContextBuilder b = share ? RequestContext.Configure().WithSharedSettings(parent)\n                                : RequestContext.Configure().WithCachePath(cache);","typeGuard":"public static bool CanShare(RequestContextBuilder b) => b.GetSettings() == null; // (requires exposing state)","tryCatchPattern":"try { return builder.WithSharedSettings(parent).Create(); }\ncatch (Exception ex) when (ex.Message.Contains(\"WithCachePath has already been made\"))\n{ return RequestContext.Configure().WithSharedSettings(parent).Create(); }","preventionTips":["Use one builder per strategy; do not reuse across share/custom calls","Reset or recreate the builder when switching strategy","Test both ordering branches"],"tags":["csharp","cefsharp","request-context","builder","fluent","misconfiguration"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}