aspnetboilerplate/aspnetboilerplate · error · ArgumentException

Requested mime type is not registered:

Error message

Requested mime type is not registered: 

What it means

MimeTypeMap.GetExtension looks up the file extension registered for a MIME type. When the MIME type has no registered extension and throwErrorIfNotFound is true, it throws ArgumentException; otherwise it returns string.Empty.

Solutions

  1. Verify the MIME type string is correct and registered; normalize (lowercase, strip parameters like '; charset=utf-8').
  2. Register a mapping first via MimeTypeMap.AddMimeType(mimeType, extension).
  3. Call with throwErrorIfNotFound: false and fall back to a default extension (e.g. ".bin").

Example fix

// before
var ext = MimeTypeMap.GetExtension(contentType);
// after
var ext = MimeTypeMap.GetExtension(contentType, throwErrorIfNotFound: false);
if (string.IsNullOrEmpty(ext)) ext = ".bin";
Defensive patterns

Strategy: fallback

Validate before calling

bool registered = !string.IsNullOrEmpty(MimeTypeMap.GetExtension(mimeType, throwErrorIfNotFound: false));

Try / catch

string ext;
try { ext = MimeTypeMap.GetExtension(mimeType); }
catch (ArgumentException) { ext = ".bin"; }

Prevention

When it happens

Trigger: Calling MimeTypeMap.GetExtension(mimeType) (or an overload with throwErrorIfNotFound: true) with a MIME type absent from the mapping dictionary, e.g. GetExtension("application/vnd.unknown+json").

Common situations: Vendor-specific or rarely used MIME types with no extension mapping; MIME types coming from HTTP Content-Type headers with parameters or slight typos; custom MIME types used before calling AddMimeType.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of aspnetboilerplate/aspnetboilerplate@2323c13a15 (2026-09-08). Data as JSON: /api/errors/09e0b868889800f0. Report an issue: GitHub.

Appendix: source

Thrown at src/Abp/MimeTypes/MimeTypeMap.cs:853

        /// <param name="throwErrorIfNotFound">if set to <c>true</c>, throws error if extension's not found.</param>
        /// <returns>The extension.</returns>
        /// <exception cref="ArgumentNullException" />
        /// <exception cref="ArgumentException" />
        public virtual string GetExtension(string mimeType, bool throwErrorIfNotFound = true)
        {
            if (string.IsNullOrWhiteSpace(mimeType))
            {
                throw new ArgumentNullException(nameof(mimeType));
            }

            if (TryGetExtension(mimeType, out string extension))
            {
                return extension;
            }

            if (throwErrorIfNotFound)
            {
                throw new ArgumentException("Requested mime type is not registered: " + mimeType);
            }

            return string.Empty;
        }

        /// <summary>
        /// Adds MIME type to map
        /// </summary>
        /// <param name="mimeType">Type of the MIME.</param>
        /// <param name="extension">Type of the extension</param>
        /// <exception cref="ArgumentNullException" />
        /// <exception cref="ArgumentException" />
        public void AddMimeType(string mimeType, string extension)
        {
            if (string.IsNullOrWhiteSpace(mimeType))
            {
                throw new ArgumentNullException(nameof(mimeType));
            }

View on GitHub (pinned to 2323c13a15)