diff --git a/iothub/device/src/ClientFactory.cs b/iothub/device/src/ClientFactory.cs index 07a5733bd6..d79b18410a 100644 --- a/iothub/device/src/ClientFactory.cs +++ b/iothub/device/src/ClientFactory.cs @@ -100,7 +100,9 @@ public static InternalClient Create(string hostname, string gatewayHostname, IAu throw new ArgumentException("No certificate was found. To use certificate authentication certificate must be present."); } +#pragma warning disable CA2000 // This is returned to client so cannot be disposed here. InternalClient dc = CreateFromConnectionString(connectionStringBuilder.ToString(), PopulateCertificateInTransportSettings(connectionStringBuilder, transportType), options); +#pragma warning restore CA2000 dc.Certificate = connectionStringBuilder.Certificate; // Install all the intermediate certificates in the chain if specified. diff --git a/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs b/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs index c0713e544e..49a3504489 100644 --- a/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs +++ b/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs @@ -69,8 +69,8 @@ public IotHubConnectionStringBuilder Populate(IotHubConnectionStringBuilder iotH throw new ArgumentNullException(nameof(iotHubConnectionStringBuilder)); } - iotHubConnectionStringBuilder.DeviceId = this.DeviceId; - iotHubConnectionStringBuilder.SharedAccessKey = this.KeyAsBase64String; + iotHubConnectionStringBuilder.DeviceId = DeviceId; + iotHubConnectionStringBuilder.SharedAccessKey = KeyAsBase64String; iotHubConnectionStringBuilder.SharedAccessKeyName = null; iotHubConnectionStringBuilder.SharedAccessSignature = null; diff --git a/iothub/device/src/Edge/EdgeModuleClientFactory.cs b/iothub/device/src/Edge/EdgeModuleClientFactory.cs index 29fd805cac..464b8eea2e 100644 --- a/iothub/device/src/Edge/EdgeModuleClientFactory.cs +++ b/iothub/device/src/Edge/EdgeModuleClientFactory.cs @@ -93,7 +93,9 @@ private async Task CreateInternalClientFromEnvironmentAsync() } ISignatureProvider signatureProvider = new HttpHsmSignatureProvider(edgedUri, DefaultApiVersion); +#pragma warning disable CA2000 // This is disposed when the client is disposed. var authMethod = new ModuleAuthenticationWithHsm(signatureProvider, deviceId, moduleId, generationId); +#pragma warning restore CA2000 Debug.WriteLine("EdgeModuleClientFactory setupTrustBundle from service"); diff --git a/iothub/device/src/InternalClient.cs b/iothub/device/src/InternalClient.cs index 975b0aaa99..a678839d1e 100644 --- a/iothub/device/src/InternalClient.cs +++ b/iothub/device/src/InternalClient.cs @@ -1974,11 +1974,17 @@ internal void ValidateModuleTransportHandler(string apiName) public void Dispose() { InnerHandler?.Dispose(); + InnerHandler = null; _methodsDictionarySemaphore?.Dispose(); _moduleReceiveMessageSemaphore?.Dispose(); _fileUploadHttpTransportHandler?.Dispose(); _deviceReceiveMessageSemaphore?.Dispose(); _twinDesiredPropertySemaphore?.Dispose(); +#if !NET451 + Certificate?.Dispose(); + Certificate = null; +#endif + IotHubConnectionString?.TokenRefresher?.Dispose(); } internal bool IsE2EDiagnosticSupportedProtocol()