Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Use ManagedCode.MimeTypes when a .NET application needs consistent MIME type detection, extension mapping, and content-type decisions for uploads, downloads, or HTTP responses. USE FOR: integrating ManagedCode.MimeTypes into upload or download flows; mapping file extensions to content types in APIs or background processing; reviewing content-type. DO NOT USE FOR: unrelated stacks; generic tasks that do not need this specific guidance. INVOKES: inspect the repository context, edit targeted files,
.claude/skills/managedcode-managedcode-mimetypes/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 1% | 0% |
| case-02 | ✗→✓ | ▲ Improved | -19% | 0% |
| case-03 | ✗→✓ | ▲ Improved | 7% | 0% |
| case-04 | ✗→✓ | ▲ Improved | 49% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 5% | 0% |
ManagedCode.MimeTypes into upload or download flowsbashdotnet add package ManagedCode.MimeTypes --version 10.0.10
Use PackageReference when the repository centralizes dependency versions:
xml<PackageReference Include="ManagedCode.MimeTypes" Version="10.0.10" />
The current package targets .NET 8, 9, and 10. Keep the version in the repository's existing central package-management file when one is present.
Map file names, URLs, and compound extensions through the generated catalog:
csharpusing ManagedCode.MimeTypes; var reportType = MimeHelper.GetMimeType("report.pdf"); var archiveType = MimeHelper.GetMimeType("archive.tar.gz"); var imageType = MimeHelper.GetMimeType("https://cdn.example.test/avatar.png?v=2"); var jpegExtensions = MimeHelper.GetExtensions("image/jpeg");
Use registry metadata when the application needs provenance or registration details:
csharpif (MimeHelper.TryGetMimeTypeInfoByExtension("report.pdf", out var info)) { Console.WriteLine($"{info.Mime} registered={info.IsIanaRegistered}"); }
Register product-specific mappings at startup and remove them only when the owning application lifecycle requires it:
csharpMimeHelper.RegisterMimeType("acme", "application/x-acme"); var customType = MimeHelper.GetMimeType("invoice.acme"); MimeHelper.UnregisterMimeType("acme");
Runtime registrations affect extension and reverse lookup, but do not synthesize full IANA registry metadata.
Treat the extension and declared content type as claims. Inspect the signature before accepting security-sensitive uploads:
csharpusing var stream = upload.OpenReadStream(); if (!MimeHelper.MatchesMimeTypeByContent(stream, upload.ContentType) || !MimeHelper.MatchesExtensionByContent(upload.FileName, stream)) { throw new InvalidOperationException("Upload content does not match its declared type."); }
GetMimeTypeByContent and the Matches*ByContent helpers inspect known prefixes and restore the position of seekable streams. They are not full document parsers, malware scanners, or proof that the remainder of a file is valid.
MimeHelper.DefaultMimeType, initially application/octet-stream; use SetDefaultMimeType only when the whole application owns a different fallback contract.MimeHelper.Instance through IMimeHelper when dependency injection and test substitution are useful; use static calls for small, deterministic mapping boundaries.10.0.10 release refreshes the generated MIME database. It adds mappings such as aaud, aimg, avid, coswid, mmdb, multitrack, and zdoc; changes mappings including dpkg, vsc, and wv; and removes stale entries such as ac2, cbor, docjson, and sarif-external-properties. Re-run product-specific mapping tests because preferred mappings can change without an API change.mermaidflowchart LR A["File name or extension"] --> B["ManagedCode.MimeTypes lookup"] B --> C["Resolved MIME type"] C --> D["Upload validation, storage metadata, or HTTP response"]
dotnet restore resolves ManagedCode.MimeTypes 10.0.10 or the repository-approved newer versiondotnet test passes for the projects that own upload, download, or storage behaviorOther measured skills in the registry, with their headline benchmark lift.