jstedfast/MailKit · error · NotSupportedException

MailKitLite does not support the COMPRESS extension.

Error message

MailKitLite does not support the COMPRESS extension.

What it means

When MailKit is compiled with the MAILKIT_LITE symbol (the MailKitLite build that omits non-essential extensions), QueueCompressCommand always throws NotSupportedException because the DEFLATE compression code path is not compiled into the Lite package at all.

Solutions

  1. Reference the full MailKit package instead of MailKitLite if COMPRESS is required
  2. Remove/guard the Compress() call when targeting MailKitLite
  3. Gate the call with a compile-time check or capability check so Lite builds skip compression

Example fix

// before
client.Compress(); // throws in MailKitLite
// after (full MailKit only)
#if !MAILKIT_LITE
if ((client.Capabilities & ImapCapabilities.Compress) != 0)
	client.Compress();
#endif
Defensive patterns

Strategy: fallback

Validate before calling

bool supportsCompress =
#if MAILKIT_LITE
	false;
#else
	(client.Capabilities & ImapCapabilities.Compress) != 0;
#endif

Try / catch

try {
	client.Compress();
} catch (NotSupportedException) {
	// Lite build or unsupported server: continue uncompressed
}

Prevention

When it happens

Trigger: Using the MailKitLite NuGet/package build and calling client.Compress() — the guard fires regardless of server capabilities.

Common situations: Migrating an app from full MailKit to MailKitLite (e.g. to reduce size or dependencies) while keeping compression calls; accidentally referencing the Lite variant when full MailKit was intended.

Understand the failure class

Background: "unsupported platform" / "not supported on this platform" errors: what they mean and how to fix them — this error's family across 47 libraries.

Related errors


AI-assisted analysis of jstedfast/MailKit@9d3859a785 (2026-09-15). Data as JSON: /api/errors/0d2b6e2f879a74a3. Report an issue: GitHub.

Appendix: source

Thrown at MailKit/Net/Imap/ImapClient.cs:298

				sslValidationInfo = new SslCertificateValidationInfo (host, certificate, chain, sslPolicyErrors);
			}

			return valid;
		}

		ImapCommand QueueCompressCommand (CancellationToken cancellationToken)
		{
			CheckDisposed ();
			CheckConnected ();

			if ((engine.Capabilities & ImapCapabilities.Compress) == 0)
				throw new NotSupportedException ("The IMAP server does not support the COMPRESS extension.");

			if (engine.State >= ImapEngineState.Selected)
				throw new InvalidOperationException ("Compression must be enabled before selecting a folder.");

#if MAILKIT_LITE
			throw new NotSupportedException ("MailKitLite does not support the COMPRESS extension.");
#else
			return engine.QueueCommand (cancellationToken, null, "COMPRESS DEFLATE\r\n");
#endif
		}

		void ProcessCompressResponse (ImapCommand ic)
		{
#if !MAILKIT_LITE
			if (ic.Response != ImapCommandResponse.Ok) {
				for (int i = 0; i < ic.RespCodes.Count; i++) {
					if (ic.RespCodes[i].Type == ImapResponseCodeType.CompressionActive)
						return;
				}

				throw ImapCommandException.Create ("COMPRESS", ic);
			}

			engine.Stream!.SetStream (new CompressedStream (engine.Stream.Stream));

View on GitHub (pinned to 9d3859a785)