diff --git a/.gitignore b/.gitignore
index daeaf68c7..bb6f58f9b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -353,6 +353,9 @@ healthchecksdb
# Backup folder for Package Reference Convert tool in Visual Studio 2017
MigrationBackup/
+# JetBrains Rider (cross platform .NET IDE) working folder
+.idea/
+
# Ionide (cross platform F# VS Code tools) working folder
.ionide/
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs
index 9cfc077da..31678a310 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBuffer.cs
@@ -811,7 +811,7 @@ namespace Microsoft.Data.SqlClient
{
if (StorageType.Guid == _type)
{
- return new SqlGuid(_value._guid);
+ return IsNull ? SqlGuid.Null : new SqlGuid(_value._guid);
}
else if (StorageType.SqlGuid == _type)
{
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 d6b8a8565..8cd1972de 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
@@ -33,6 +33,7 @@
+
diff --git a/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs
new file mode 100644
index 000000000..6aef4b60b
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/tests/FunctionalTests/SqlBufferTests.cs
@@ -0,0 +1,253 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+// See the LICENSE file in the project root for more information.
+
+using System;
+using System.Collections.Generic;
+using System.Data.SqlTypes;
+using System.Linq;
+using System.Reflection;
+using Xunit;
+
+namespace Microsoft.Data.SqlClient.Tests
+{
+ public sealed class SqlBufferTests
+ {
+ static SqlBufferTests()
+ {
+ const string sqlBufferTypeFullName = "Microsoft.Data.SqlClient.SqlBuffer";
+ const string storageTypeName = nameof(SqlBufferProxy.StorageType);
+
+ var assembly = typeof(SqlClientFactory).Assembly;
+ _sqlBufferType = assembly.GetType(sqlBufferTypeFullName)
+ ?? throw new Exception($"Type not found [{sqlBufferTypeFullName}]");
+ _storageTypeType = _sqlBufferType.GetNestedTypes(BindingFlags.NonPublic)
+ .FirstOrDefault(x => x.Name == storageTypeName)
+ ?? throw new Exception($"Type not found [{sqlBufferTypeFullName}+{storageTypeName}]");
+ }
+
+ private static readonly Type _sqlBufferType;
+ private static readonly Type _storageTypeType;
+ private readonly SqlBufferProxy _target = new();
+
+ public static IEnumerable