diff --git a/iothub/device/src/DeviceClient.cs b/iothub/device/src/DeviceClient.cs
index 43966a49c6..57e91e77a2 100644
--- a/iothub/device/src/DeviceClient.cs
+++ b/iothub/device/src/DeviceClient.cs
@@ -15,7 +15,7 @@ namespace Microsoft.Azure.Devices.Client
/// Contains methods that a device can use to send messages to and receive from the service.
///
///
- public sealed class DeviceClient : IDisposable
+ public class DeviceClient : IDisposable
{
///
/// Default operation timeout.
@@ -608,7 +608,25 @@ public void SetConnectionStatusChangesHandler(ConnectionStatusChangesHandler sta
///
/// Releases the unmanaged resources used by the DeviceClient and optionally disposes of the managed resources.
///
- public void Dispose() => InternalClient?.Dispose();
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Releases the unmanaged resources used by the DeviceClient and allows for any derived class to override and
+ /// provide custom implementation.
+ ///
+ /// Setting to true will release both managed and unmanaged resources.
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ InternalClient?.Dispose();
+ InternalClient = null;
+ }
+ }
///
/// Set a callback that will be called whenever the client receives a state update
diff --git a/iothub/device/src/ModuleClient.cs b/iothub/device/src/ModuleClient.cs
index 901a84d57e..aee3b0a706 100644
--- a/iothub/device/src/ModuleClient.cs
+++ b/iothub/device/src/ModuleClient.cs
@@ -21,7 +21,7 @@ namespace Microsoft.Azure.Devices.Client
///
/// Contains methods that a module can use to send messages to and receive from the service and interact with module twins.
///
- public sealed class ModuleClient : IDisposable
+ public class ModuleClient : IDisposable
{
private const string ModuleMethodUriFormat = "/twins/{0}/modules/{1}/methods?" + ClientApiVersionHelper.ApiVersionQueryStringLatest;
private const string DeviceMethodUriFormat = "/twins/{0}/methods?" + ClientApiVersionHelper.ApiVersionQueryStringLatest;
@@ -433,7 +433,25 @@ public void SetConnectionStatusChangesHandler(ConnectionStatusChangesHandler sta
///
/// Releases the unmanaged resources used by the ModuleClient and optionally disposes of the managed resources.
///
- public void Dispose() => InternalClient?.Dispose();
+ public void Dispose()
+ {
+ Dispose(true);
+ GC.SuppressFinalize(this);
+ }
+
+ ///
+ /// Releases the unmanaged resources used by the ModuleClient and allows for any derived class to override and
+ /// provide custom implementation.
+ ///
+ /// Setting to true will release both managed and unmanaged resources.
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ InternalClient?.Dispose();
+ InternalClient = null;
+ }
+ }
///
/// Set a callback that will be called whenever the client receives a state update