diff --git a/CryptoExchange.Net/Authentication/ApiCredentials.cs b/CryptoExchange.Net/Authentication/ApiCredentials.cs
index 18355c0..92e1350 100644
--- a/CryptoExchange.Net/Authentication/ApiCredentials.cs
+++ b/CryptoExchange.Net/Authentication/ApiCredentials.cs
@@ -70,7 +70,7 @@ namespace CryptoExchange.Net.Authentication
public virtual ApiCredentials Copy()
{
if (PrivateKey == null)
- return new ApiCredentials(Key!.GetString(), Secret!.GetString());
+ return new ApiCredentials(Key!, Secret!);
else
return new ApiCredentials(PrivateKey!.Copy());
}
diff --git a/CryptoExchange.Net/Clients/BaseApiClient.cs b/CryptoExchange.Net/Clients/BaseApiClient.cs
index 03aadbc..91f039b 100644
--- a/CryptoExchange.Net/Clients/BaseApiClient.cs
+++ b/CryptoExchange.Net/Clients/BaseApiClient.cs
@@ -12,6 +12,7 @@ namespace CryptoExchange.Net
private ApiCredentials? _apiCredentials;
private AuthenticationProvider? _authenticationProvider;
private bool _created;
+ private bool _disposing;
///
/// The authentication provider for this API client. (null if no credentials are set)
@@ -20,7 +21,7 @@ namespace CryptoExchange.Net
{
get
{
- if (!_created && _apiCredentials != null)
+ if (!_created && !_disposing && _apiCredentials != null)
{
_authenticationProvider = CreateAuthenticationProvider(_apiCredentials);
_created = true;
@@ -62,7 +63,7 @@ namespace CryptoExchange.Net
///
public void SetApiCredentials(ApiCredentials credentials)
{
- _apiCredentials = credentials;
+ _apiCredentials = credentials?.Copy();
_created = false;
_authenticationProvider = null;
}
@@ -72,6 +73,8 @@ namespace CryptoExchange.Net
///
public void Dispose()
{
+ _disposing = true;
+ _apiCredentials?.Dispose();
AuthenticationProvider?.Credentials?.Dispose();
}
}
diff --git a/CryptoExchange.Net/Objects/Options.cs b/CryptoExchange.Net/Objects/Options.cs
index 94cf6ec..16f5eb9 100644
--- a/CryptoExchange.Net/Objects/Options.cs
+++ b/CryptoExchange.Net/Objects/Options.cs
@@ -260,7 +260,7 @@ namespace CryptoExchange.Net.Objects
///
/// Copy values for the provided options
#pragma warning disable 8618 // Will always get filled by the provided options
- public ApiClientOptions(ApiClientOptions baseOptions, RestApiClientOptions? newValues)
+ public ApiClientOptions(ApiClientOptions baseOptions, ApiClientOptions? newValues)
{
BaseAddress = newValues?.BaseAddress ?? baseOptions.BaseAddress;
ApiCredentials = newValues?.ApiCredentials?.Copy() ?? baseOptions.ApiCredentials?.Copy();
@@ -318,7 +318,7 @@ namespace CryptoExchange.Net.Objects
/// ctor
///
/// Copy values for the provided options
- public RestApiClientOptions(RestApiClientOptions baseOn, RestApiClientOptions newValues): base(baseOn, newValues)
+ public RestApiClientOptions(RestApiClientOptions baseOn, RestApiClientOptions? newValues): base(baseOn, newValues)
{
RateLimitingBehaviour = newValues?.RateLimitingBehaviour ?? baseOn.RateLimitingBehaviour;
AutoTimestamp = newValues?.AutoTimestamp ?? baseOn.AutoTimestamp;