Cannot correctly use LdapSessionOptions.StopTransportLayerSecurity without tracking state locally #49726
Labels
area-System.DirectoryServices
enhancement
Product code improvement that does NOT require public API changes/additions
Milestone
Description
It's obvious that we should always dispose of an
LdapConnection
instance via ausing
statement (or similar).To use LDAP with TLS, we're supposed to call the relevant "start" method on the session options instance. I assume, but it's not documented, that we should attempt to stop TLS if we started it. I'm thinking a
try
...finally
block?However, if, for whatever reason, it's the start method call that fails leading to the stop method call in the finally block, the stop method will throw a
TlsOperationException
, which is documented. But, that means, I need to either wrap that call or track a local Boolean.This is kind of a hot mess, right? Is there any way to get a
bool
returned by the start/stop methods? or for the session options to track this state like it does for "secure socket layer" (if that is, in fact, what is happening there)?Configuration
.NET 5.0 on Windows 10 and Debian Linux.
Regression?
Other information
The text was updated successfully, but these errors were encountered: