cefsharp/CefSharp · error · ArgumentNullException
Please provide a valid mimeType
Error message
Please provide a valid mimeType
What it means
Thrown by the legacy ResourceHandler constructor when the mimeType argument is null or empty. Although it is a value-required error, the code uses ArgumentNullException with 'mimeType' as the paramName. The parameter defaults to CefSharp.ResourceHandler.DefaultMimeType, so this only fires when the caller explicitly passes null or empty.
Solutions
- Default the argument by not passing it, or pass CefSharp.ResourceHandler.DefaultMimeType explicitly.
- Coalesce: mimeType ?? CefSharp.ResourceHandler.DefaultMimeType.
- Resolve the MIME from the file extension (e.g. MimeMapping) before constructing.
- Validate the MIME is non-empty at the call site.
Example fix
// before var h = new ResourceHandler(mimeType: resolvedMimeType); // null -> throws // after var mt = string.IsNullOrEmpty(resolvedMimeType) ? CefSharp.ResourceHandler.DefaultMimeType : resolvedMimeType; var h = new ResourceHandler(mimeType: mt);
Defensive patterns
Strategy: validation
Validate before calling
var mime = string.IsNullOrEmpty(resolved) ? CefSharp.ResourceHandler.DefaultMimeType : resolved; var handler = new ResourceHandler(mime);
Try / catch
try { var h = new ResourceHandler(mime); }
catch (ArgumentNullException ex) when (ex.ParamName == "mimeType")
{ var h = new ResourceHandler(CefSharp.ResourceHandler.DefaultMimeType); } Prevention
- Coalesce null/empty MIME to DefaultMimeType.
- Resolve MIME from extension before constructing.
- Omit the argument to take the default.
When it happens
Trigger: Constructing new ResourceHandler(mimeType: null) or new ResourceHandler("") (e.g. forwarding a request MIME type that was unset); code that derives the MIME from content and passes through a null.
Common situations: Passing a computed/looked-up MIME that returned null; clearing a header value before constructing; legacy code migrating from an overload that allowed null.
Related errors
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/078848fe0f24d4e7.
Report an issue: GitHub.
Appendix: source
Thrown at CefSharp/Lagacy/ResourceHandler.cs:83
/// <summary>
/// If the ErrorCode is set then the response will be ignored and
/// the errorCode returned.
/// </summary>
public CefErrorCode? ErrorCode { get; set; }
/// <summary>
/// Initializes a new instance of the <see cref="ResourceHandler"/> class.
/// </summary>
/// <param name="mimeType">Optional mimeType defaults to <see cref="CefSharp.ResourceHandler.DefaultMimeType"/></param>
/// <param name="stream">Optional Stream - must be set at some point to provide a valid response</param>
/// <param name="autoDisposeStream">When true the Stream will be disposed when this instance is Diposed, you will
/// be unable to use this ResourceHandler after the Stream has been disposed</param>
/// <param name="charset">response charset</param>
public ResourceHandler(string mimeType = CefSharp.ResourceHandler.DefaultMimeType, Stream stream = null, bool autoDisposeStream = false, string charset = null)
{
if (string.IsNullOrEmpty(mimeType))
{
throw new ArgumentNullException("mimeType", "Please provide a valid mimeType");
}
StatusCode = 200;
StatusText = "OK";
MimeType = mimeType;
Headers = new NameValueCollection();
Stream = stream;
AutoDisposeStream = autoDisposeStream;
Charset = charset;
}
/// <summary>
/// Begin processing the request. If you have the data in memory you can execute the callback
/// immediately and return true. For Async processing you would typically spawn a Task to perform processing,
/// then return true. When the processing is complete execute callback.Continue(); In your processing Task, simply set
/// the StatusCode, StatusText, MimeType, ResponseLength and Stream
/// </summary>
/// <param name="request">The request object.</param>View on GitHub (pinned to 16bc6e0711)