{"record":{"id":"b01471a142a4e94d","repo":"jstedfast/MailKit","slug":"capabilities-cannot-be-enabled-they-may-only-be-disabled","errorCode":null,"errorMessage":"Capabilities cannot be enabled, they may only be disabled.","messagePattern":"Capabilities cannot be enabled, they may only be disabled\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"MailKit/Net/Imap/ImapClient.cs","lineNumber":174,"sourceCode":"\t\t/// <remarks>\n\t\t/// The capabilities will not be known until a successful connection has been made via one of\n\t\t/// the <a href=\"Overload_MailKit_Net_Imap_ImapClient_Connect.htm\">Connect</a> methods and may\n\t\t/// change as a side-effect of calling one of the\n\t\t/// <a href=\"Overload_MailKit_Net_Imap_ImapClient_Authenticate.htm\">Authenticate</a>\n\t\t/// methods.\n\t\t/// </remarks>\n\t\t/// <example>\n\t\t/// <code language=\"c#\" source=\"Examples\\ImapExamples.cs\" region=\"Capabilities\"/>\n\t\t/// </example>\n\t\t/// <value>The capabilities.</value>\n\t\t/// <exception cref=\"System.ArgumentException\">\n\t\t/// Capabilities cannot be enabled, they may only be disabled.\n\t\t/// </exception>\n\t\tpublic ImapCapabilities Capabilities {\n\t\t\tget { return engine.Capabilities; }\n\t\t\tset {\n\t\t\t\tif ((engine.Capabilities | value) > engine.Capabilities)\n\t\t\t\t\tthrow new ArgumentException (\"Capabilities cannot be enabled, they may only be disabled.\", nameof (value));\n\n\t\t\t\tengine.Capabilities = value;\n\t\t\t}\n\t\t}\n\n\t\t/// <summary>\n\t\t/// Get the maximum size of a message that can be appended to a folder.\n\t\t/// </summary>\n\t\t/// <remarks>\n\t\t/// <para>Gets the maximum size of a message, in bytes, that can be appended to a folder.</para>\n\t\t/// <note type=\"note\">If the value is not set, then the limit is unspecified.</note>\n\t\t/// </remarks>\n\t\t/// <value>The append limit.</value>\n\t\tpublic uint? AppendLimit {\n\t\t\tget { return engine.AppendLimit; }\n\t\t}\n\n\t\t/// <summary>","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/jstedfast/MailKit/blob/9d3859a7855e3e17582c07fd01972b8e262bf176/MailKit/Net/Imap/ImapClient.cs#L156-L192","documentation":"ImapClient.Capabilities is settable only to REMOVE capabilities (a mask of features the client should pretend not to support). The setter throws ArgumentException if the value would enable any capability not already present, because MailKit never allows the client to invent capabilities the server did not offer.","triggerScenarios":"Assigning `client.Capabilities = ImapCapabilities.QuickResync` (or OR-ing in new bits) when that bit is not already in engine.Capabilities, e.g. copying a capabilities enum from another client or using bitwise OR instead of AND-NOT.","commonSituations":"Trying to force-enable an extension the server didn't advertise; misunderstanding the property as a general set (it is a disable-mask); migrating code that set capabilities on a different library.","solutions":["Only assign values that are a subset of the current Capabilities (use AND to intersect)","To disable a feature, use value &= ~ImapCapabilities.SomeBit or Capabilities & ~flag","To use an extension, the SERVER must support it — verify with client.Capabilities after connecting"],"exampleFix":"// before\nclient.Capabilities |= ImapCapabilities.Condstore; // would ENABLE - throws\n// after\nclient.Capabilities &= ~ImapCapabilities.Condstore; // disable only","handlingStrategy":"validation","validationCode":"if ((client.Capabilities | value) > client.Capabilities)\n\tthrow new InvalidOperationException(\"Capabilities mask may only remove features.\");","typeGuard":"bool IsCapabilitySubset(ImapCapabilities current, ImapCapabilities value)\n\t=> (current | value) == current;","tryCatchPattern":"try {\n\tclient.Capabilities = mask;\n} catch (ArgumentException) {\n\tclient.Capabilities = client.Capabilities & mask; // intersect instead\n}","preventionTips":["Treat ImapClient.Capabilities as a disable-mask only","Build masks with & ~ rather than |=","Never attempt to enable extensions the server didn't advertise"],"tags":["imap","argument-validation","capabilities","api-misuse"],"backgroundTag":"invalid-argument-value","analyzedSha":"9d3859a7855e3e17582c07fd01972b8e262bf176","analyzedAt":"2026-09-15T15:46:11.592Z","contentChangedAt":"2026-09-15T15:46:11.592Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}