diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs index 98f517ea17..a675e738bc 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -111,7 +111,7 @@ private enum EXECTYPE // cached metadata private _SqlMetaDataSet _cachedMetaData; - private Dictionary keysToBeSentToEnclave = new Dictionary(); + private Dictionary keysToBeSentToEnclave; private bool requiresEnclaveComputations = false; internal EnclavePackage enclavePackage = null; private SqlEnclaveAttestationParameters enclaveAttestationParameters = null; @@ -2994,8 +2994,10 @@ private void ResetEncryptionState() _parameters[i].HasReceivedMetadata = false; } } - - keysToBeSentToEnclave.Clear(); + if (keysToBeSentToEnclave != null) + { + keysToBeSentToEnclave.Clear(); + } enclavePackage = null; requiresEnclaveComputations = false; enclaveAttestationParameters = null; @@ -3728,10 +3730,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi { throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count); } - - if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal)) + if (keysToBeSentToEnclave == null) + { + keysToBeSentToEnclave = new Dictionary(); + keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); + } + else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal)) { - this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); + keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); } requiresEnclaveComputations = true; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs index 3993e01e2e..5caa018baa 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlCommand.cs @@ -121,7 +121,7 @@ private enum EXECTYPE // cached metadata private _SqlMetaDataSet _cachedMetaData; - private Dictionary keysToBeSentToEnclave = new Dictionary(); + private Dictionary keysToBeSentToEnclave; private bool requiresEnclaveComputations = false; internal EnclaveDelegate.EnclavePackage enclavePackage = null; private SqlEnclaveAttestationParameters enclaveAttestationParameters = null; @@ -3872,7 +3872,10 @@ private void ResetEncryptionState() } } - keysToBeSentToEnclave.Clear(); + if (keysToBeSentToEnclave != null) + { + keysToBeSentToEnclave.Clear(); + } enclavePackage = null; requiresEnclaveComputations = false; enclaveAttestationParameters = null; @@ -4666,9 +4669,14 @@ private void ReadDescribeEncryptionParameterResults(SqlDataReader ds, ReadOnlyDi throw SQL.InvalidEncryptionKeyOrdinalEnclaveMetadata(requestedKey, columnEncryptionKeyTable.Count); } - if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal)) + if (keysToBeSentToEnclave == null) + { + keysToBeSentToEnclave = new Dictionary(); + keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); + } + else if (!keysToBeSentToEnclave.ContainsKey(currentOrdinal)) { - this.keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); + keysToBeSentToEnclave.Add(currentOrdinal, cipherInfo); } requiresEnclaveComputations = true;