From c7de60b0ac4a0cafbf87c843ba0c69482d6edcaf Mon Sep 17 00:00:00 2001
From: dauinsight <145612907+dauinsight@users.noreply.github.com>
Date: Mon, 26 Aug 2024 15:27:15 -0700
Subject: [PATCH] [5.2.2] | Fix ArgumentNullException on SqlDataRecord.GetValue
when using Udt data type (#2448) (#2816)
---
.../Data/SqlClient/Server/MetadataUtilsSmi.cs | 4 ---
.../Microsoft.Data.SqlClient.Tests.csproj | 2 ++
.../FunctionalTests/SqlDataRecordTest.cs | 35 ++++++++++++++++++-
3 files changed, 36 insertions(+), 5 deletions(-)
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/MetadataUtilsSmi.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/MetadataUtilsSmi.cs
index 590429222a..2dc635320b 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/MetadataUtilsSmi.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Server/MetadataUtilsSmi.cs
@@ -500,11 +500,7 @@ internal static SmiExtendedMetaData SqlMetaDataToSmiExtendedMetaData(SqlMetaData
source.Scale,
source.LocaleId,
source.CompareOptions,
-#if NETFRAMEWORK
source.Type,
-#else
- null,
-#endif
source.Name,
typeSpecificNamePart1,
typeSpecificNamePart2,
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj
index 7724f4c58e..506960d3b6 100644
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj
+++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/Microsoft.Data.SqlClient.Tests.csproj
@@ -94,6 +94,8 @@
+
+
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs
index 87f6c167ec..0e748c5d74 100644
--- a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs
+++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlDataRecordTest.cs
@@ -8,6 +8,7 @@
using System.Data;
using System.Data.SqlTypes;
using Microsoft.Data.SqlClient.Server;
+using Microsoft.SqlServer.Types;
using Xunit;
namespace Microsoft.Data.SqlClient.Tests
@@ -318,6 +319,19 @@ public void GetChar_ThrowsNotSupported()
Assert.Throws(() => record.GetChar(0));
}
+ [Theory]
+ [ClassData(typeof(GetUdtTypeTestData))]
+ public void GetUdt_ReturnsValue(Type udtType, object value, string serverTypeName)
+ {
+ SqlMetaData[] metadata = new SqlMetaData[] { new SqlMetaData(nameof(udtType.Name), SqlDbType.Udt, udtType, serverTypeName) };
+
+ SqlDataRecord record = new SqlDataRecord(metadata);
+
+ record.SetValue(0, value);
+
+ Assert.Equal(value.ToString(), record.GetValue(0).ToString());
+ }
+
[Theory]
[ClassData(typeof(GetXXXBadTypeTestData))]
public void GetXXX_ThrowsIfBadType(Func getXXX)
@@ -342,8 +356,8 @@ public void GetXXX_ReturnValue(SqlDbType dbType, object value, Func
+ {
+ public IEnumerator