{"record":{"id":"d498c0527f64c33c","repo":"cefsharp/CefSharp","slug":"a-call-to-withsharedsettings-has-already-been-made","errorCode":null,"errorMessage":"A call to WithSharedSettings has already been made, it is no possible to provide custom settings.","messagePattern":"A call to WithSharedSettings has already been made, it is no possible to provide custom settings\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.Core/RequestContextBuilder.cs","lineNumber":25,"sourceCode":"using CefSharp.Handler;\nusing System;\n\nnamespace CefSharp\n{\n    /// <summary>\n    /// Fluent style builder for creating IRequestContext instances.\n    /// </summary>\n    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            {","sourceCodeStart":7,"sourceCodeEnd":43,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.Core/RequestContextBuilder.cs#L7-L43","documentation":"Thrown by RequestContextBuilder.ThrowExceptionIfContextAlreadySet (a plain System.Exception, not a domain type) when you call a method that sets custom settings (e.g. WithCachePath) after WithSharedSettings has already stored an _otherContext. The builder cannot both share another context's storage and apply its own settings, so it rejects the contradictory configuration. Note the message typo 'no possible'.","triggerScenarios":"Chaining .WithSharedSettings(parent).WithCachePath(...) on the same builder; calling WithCachePath twice after a share; any settings mutation after WithSharedSettings.","commonSituations":"Copy-pasted builder configuration where one branch shares and another customises; refactoring that merged two builders; misunderstanding that sharing and customising are mutually exclusive.","solutions":["Decide on one strategy: either share via WithSharedSettings OR customise via WithCachePath/WithPreference, never both.","Split into two separate RequestContextBuilder instances if you need both kinds of contexts.","Call WithCachePath before any WithSharedSettings is impossible (sharing wins once set), so reorder: build your custom context first if needed.","Track builder state in your own code so the two paths are mutually exclusive at the source."],"exampleFix":"// before - contradictory\nvar ctx = RequestContext.Configure()\n    .WithSharedSettings(parent)\n    .WithCachePath(@\"C:\\cache\") // throws\n    .Create();\n\n// after - pick one\nvar shared = RequestContext.Configure().WithSharedSettings(parent).Create();\n// or\nvar custom = RequestContext.Configure().WithCachePath(@\"C:\\cache\").Create();","handlingStrategy":"validation","validationCode":"// Enforce one strategy before building.\nRequestContextBuilder Build(bool share, IRequestContext parent, string cache)\n{\n    var b = RequestContext.Configure();\n    if (share) return b.WithSharedSettings(parent);\n    return b.WithCachePath(cache);\n}","typeGuard":"public static bool CanAddCustomSettings(RequestContextBuilder b) => b.GetOtherContext() == null; // (requires exposing state)","tryCatchPattern":"try { return builder.WithCachePath(path).Create(); }\ncatch (Exception ex) when (ex.Message.Contains(\"WithSharedSettings has already been made\"))\n{ /* use a fresh builder for custom settings */ return RequestContext.Configure().WithCachePath(path).Create(); }","preventionTips":["Never chain WithSharedSettings and WithCachePath on one builder","Use a dedicated builder per strategy","Add integration tests covering both code paths"],"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"}