cefsharp/CefSharp · error · Exception
A call to WithCachePath has already been made, it's not poss
Error message
A call to WithCachePath has already been made, it's not possible to share settings with another RequestContext.
What it means
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.
Source
Thrown at CefSharp.Core/RequestContextBuilder.cs:33
public class RequestContextBuilder
{
private RequestContextSettings _settings;
private IRequestContext _otherContext;
private RequestContextHandler _handler;
void ThrowExceptionIfContextAlreadySet()
{
if (_otherContext != null)
{
throw new Exception("A call to WithSharedSettings has already been made, it is no possible to provide custom settings.");
}
}
void ThrowExceptionIfCustomSettingSpecified()
{
if (_settings != null)
{
throw new Exception("A call to WithCachePath has already been made, it's not possible to share settings with another RequestContext.");
}
}
/// <summary>
/// Create the actual RequestContext instance
/// </summary>
/// <returns>Returns a new RequestContext instance.</returns>
public IRequestContext Create()
{
if (_otherContext != null)
{
return new CefSharp.Core.RequestContext(_otherContext, _handler);
}
if (_settings != null)
{
return new CefSharp.Core.RequestContext(_settings.settings, _handler);
}
View on GitHub (pinned to 16bc6e0711)
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.
Example fix
// before - throws
var ctx = RequestContext.Configure()
.WithCachePath(@"C:\cache")
.WithSharedSettings(parent) // throws
.Create();
// after - one strategy per builder
var custom = RequestContext.Configure().WithCachePath(@"C:\cache").Create(); Defensive patterns
Strategy: validation
Validate before calling
// Decide share-vs-customise before configuring the builder.
RequestContextBuilder b = share ? RequestContext.Configure().WithSharedSettings(parent)
: RequestContext.Configure().WithCachePath(cache); Type guard
public static bool CanShare(RequestContextBuilder b) => b.GetSettings() == null; // (requires exposing state)
Try / catch
try { return builder.WithSharedSettings(parent).Create(); }
catch (Exception ex) when (ex.Message.Contains("WithCachePath has already been made"))
{ return RequestContext.Configure().WithSharedSettings(parent).Create(); } Prevention
- Use one builder per strategy; do not reuse across share/custom calls
- Reset or recreate the builder when switching strategy
- Test both ordering branches
When it happens
Trigger: Chaining .WithCachePath(...).WithSharedSettings(parent); calling WithSharedSettings twice after a custom setting was added; merging a shared and a custom configuration in one builder.
Common situations: 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.
Related errors
- A call to WithSharedSettings has already been made, it is no
- other
- otherRequestContext
- requestContextHandler
- settings
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/b1e40896de122ade.
Report an issue: GitHub.