From f2979e1f4567e12d58198c701060a12b3d860086 Mon Sep 17 00:00:00 2001 From: Sindhu Nagesh Date: Tue, 2 Feb 2021 14:06:45 -0800 Subject: [PATCH] (fix): Build error due to missing dispose --- iothub/device/src/AuthenticationWithTokenRefresh.cs | 2 +- iothub/device/src/ClientFactory.cs | 4 +++- .../DeviceAuthenticationWithRegistrySymmetricKey.cs | 10 ++++++++-- .../DeviceAuthenticationWithSharedAccessPolicyKey.cs | 6 ++++++ iothub/device/src/DeviceAuthenticationWithToken.cs | 6 ++++++ .../src/DeviceAuthenticationWithX509Certificate.cs | 6 ++++++ iothub/device/src/IAuthenticationMethod.cs | 4 +++- iothub/device/src/IAuthorizationProvider.cs | 3 ++- iothub/device/src/InternalClient.cs | 7 +++++++ iothub/device/src/IotHubConnectionString.cs | 6 ++++++ .../ModuleAuthenticationWithRegistrySymmetricKey.cs | 6 ++++++ iothub/device/src/ModuleAuthenticationWithToken.cs | 6 ++++++ 12 files changed, 60 insertions(+), 6 deletions(-) diff --git a/iothub/device/src/AuthenticationWithTokenRefresh.cs b/iothub/device/src/AuthenticationWithTokenRefresh.cs index c68267e2c8..517d414022 100644 --- a/iothub/device/src/AuthenticationWithTokenRefresh.cs +++ b/iothub/device/src/AuthenticationWithTokenRefresh.cs @@ -12,7 +12,7 @@ namespace Microsoft.Azure.Devices.Client /// /// Authentication method that uses a shared access signature token and allows for token refresh. /// - public abstract class AuthenticationWithTokenRefresh : IAuthenticationMethod, IDisposable + public abstract class AuthenticationWithTokenRefresh : IAuthenticationMethod { private readonly int _suggestedTimeToLiveSeconds; private readonly int _timeBufferPercentage; diff --git a/iothub/device/src/ClientFactory.cs b/iothub/device/src/ClientFactory.cs index 07a5733bd6..34e7fd8f2a 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. @@ -158,7 +160,7 @@ public static InternalClient Create(string hostname, string gatewayHostname, IAu throw new ArgumentNullException(nameof(authenticationMethod)); } - var connectionStringBuilder = IotHubConnectionStringBuilder.Create(hostname, gatewayHostname, authenticationMethod); + IotHubConnectionStringBuilder connectionStringBuilder = IotHubConnectionStringBuilder.Create(hostname, gatewayHostname, authenticationMethod); // Make sure client options is initialized with the correct transport setting. EnsureOptionsIsSetup(connectionStringBuilder.Certificate, ref options); diff --git a/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs b/iothub/device/src/DeviceAuthenticationWithRegistrySymmetricKey.cs index c0713e544e..24fcc9c445 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; @@ -106,5 +106,11 @@ private void SetDeviceId(string deviceId) _deviceId = deviceId; } + + /// + + public void Dispose() + { + } } } diff --git a/iothub/device/src/DeviceAuthenticationWithSharedAccessPolicyKey.cs b/iothub/device/src/DeviceAuthenticationWithSharedAccessPolicyKey.cs index b972935ca9..de1d7ce33b 100644 --- a/iothub/device/src/DeviceAuthenticationWithSharedAccessPolicyKey.cs +++ b/iothub/device/src/DeviceAuthenticationWithSharedAccessPolicyKey.cs @@ -55,6 +55,12 @@ public string PolicyName set => SetPolicyName(value); } + /// + + public void Dispose() + { + } + /// /// Populates an instance based on the properties of the current instance. /// diff --git a/iothub/device/src/DeviceAuthenticationWithToken.cs b/iothub/device/src/DeviceAuthenticationWithToken.cs index 957bbe38f8..f10d8ebb6a 100644 --- a/iothub/device/src/DeviceAuthenticationWithToken.cs +++ b/iothub/device/src/DeviceAuthenticationWithToken.cs @@ -43,6 +43,12 @@ public string Token set => SetToken(value); } + /// + + public void Dispose() + { + } + /// /// Populates an instance based on the properties of the current instance. /// diff --git a/iothub/device/src/DeviceAuthenticationWithX509Certificate.cs b/iothub/device/src/DeviceAuthenticationWithX509Certificate.cs index 0a60b7fc46..1e28bd0967 100644 --- a/iothub/device/src/DeviceAuthenticationWithX509Certificate.cs +++ b/iothub/device/src/DeviceAuthenticationWithX509Certificate.cs @@ -48,6 +48,12 @@ public string DeviceId /// public X509Certificate2Collection ChainCertificates { get; } + /// + + public void Dispose() + { + } + /// /// Populates an instance based on the properties of the current instance. /// diff --git a/iothub/device/src/IAuthenticationMethod.cs b/iothub/device/src/IAuthenticationMethod.cs index 4661180e81..4c37efe1e3 100644 --- a/iothub/device/src/IAuthenticationMethod.cs +++ b/iothub/device/src/IAuthenticationMethod.cs @@ -1,12 +1,14 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; + namespace Microsoft.Azure.Devices.Client { /// /// Authentication interface to use for device communications. /// - public interface IAuthenticationMethod + public interface IAuthenticationMethod : IDisposable { /// /// Populates an instance based on the properties of the current instance. diff --git a/iothub/device/src/IAuthorizationProvider.cs b/iothub/device/src/IAuthorizationProvider.cs index fb0113fd1f..5a2cd41637 100644 --- a/iothub/device/src/IAuthorizationProvider.cs +++ b/iothub/device/src/IAuthorizationProvider.cs @@ -1,11 +1,12 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using System; using System.Threading.Tasks; namespace Microsoft.Azure.Devices.Client { - internal interface IAuthorizationProvider + internal interface IAuthorizationProvider : IDisposable { Task GetPasswordAsync(); } diff --git a/iothub/device/src/InternalClient.cs b/iothub/device/src/InternalClient.cs index 975b0aaa99..5dd6e09438 100644 --- a/iothub/device/src/InternalClient.cs +++ b/iothub/device/src/InternalClient.cs @@ -1974,11 +1974,18 @@ 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?.Dispose(); + IotHubConnectionString = null; } internal bool IsE2EDiagnosticSupportedProtocol() diff --git a/iothub/device/src/IotHubConnectionString.cs b/iothub/device/src/IotHubConnectionString.cs index 8dc0db6088..77687cccb1 100644 --- a/iothub/device/src/IotHubConnectionString.cs +++ b/iothub/device/src/IotHubConnectionString.cs @@ -96,5 +96,11 @@ public IotHubConnectionString(IotHubConnectionStringBuilder builder) public string SharedAccessKey { get; private set; } public string SharedAccessSignature { get; private set; } + + public void Dispose() + { + TokenRefresher?.Dispose(); + TokenRefresher = null; + } } } diff --git a/iothub/device/src/ModuleAuthenticationWithRegistrySymmetricKey.cs b/iothub/device/src/ModuleAuthenticationWithRegistrySymmetricKey.cs index 921dfbd772..7085fb758e 100644 --- a/iothub/device/src/ModuleAuthenticationWithRegistrySymmetricKey.cs +++ b/iothub/device/src/ModuleAuthenticationWithRegistrySymmetricKey.cs @@ -128,5 +128,11 @@ private void SetModuleId(string moduleId) _moduleId = moduleId; } + + /// + + public void Dispose() + { + } } } diff --git a/iothub/device/src/ModuleAuthenticationWithToken.cs b/iothub/device/src/ModuleAuthenticationWithToken.cs index e6516994b6..f353e2b184 100644 --- a/iothub/device/src/ModuleAuthenticationWithToken.cs +++ b/iothub/device/src/ModuleAuthenticationWithToken.cs @@ -55,6 +55,12 @@ public string Token set => SetToken(value); } + /// + + public void Dispose() + { + } + /// /// Populates an instance based on the properties of the current instance. ///