Skip to content

Commit 7b1b4e5

Browse files
committed
Throw InvalidCastException when GetGuid fails.
This is a breaking API change from Connector/NET, but matches other ADO.NET connectors.
1 parent 01dc76f commit 7b1b4e5

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

src/MySqlConnector/Core/Row.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,7 @@ public Guid GetGuid(int ordinal)
141141
if (value is byte[] bytes && bytes.Length == 16)
142142
return new Guid(bytes);
143143

144-
if (m_dataOffsets[ordinal] == -1)
145-
throw new InvalidCastException("Column is NULL.");
146-
throw new MySqlException("The value could not be converted to a GUID: {0}".FormatInvariant(value));
144+
throw new InvalidCastException("The value could not be converted to a GUID: {0}".FormatInvariant(value));
147145
}
148146

149147
public short GetInt16(int ordinal)

tests/SideBySide/DataTypes.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ public async Task GetGuid(string column, Type fieldType)
394394
Assert.NotNull(reader.GetValue(0));
395395
Assert.IsType(fieldType, reader.GetValue(0));
396396

397-
Type exceptionType = typeof(MySqlException);
397+
Type exceptionType = typeof(GetGuidWhenNullException);
398398
#if BASELINE
399399
// baseline throws FormatException when conversion from string fails
400400
if (fieldType == typeof(string))

0 commit comments

Comments
 (0)