Skip to content

Commit eb7a8f9

Browse files
authored
Fix type info cache being constructed with the wrong type (#5370)
1 parent cd59e21 commit eb7a8f9

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

src/Npgsql/Internal/PgSerializerOptions.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ public sealed class PgSerializerOptions
1616
internal static bool IntrospectionCaller { get; set; }
1717

1818
readonly Func<string>? _timeZoneProvider;
19-
readonly object _typeInfoCache;
19+
object? _typeInfoCache;
2020

2121
internal PgSerializerOptions(NpgsqlDatabaseInfo databaseInfo, Func<string>? timeZoneProvider = null)
2222
{
2323
_timeZoneProvider = timeZoneProvider;
2424
DatabaseInfo = databaseInfo;
2525
UnknownPgType = databaseInfo.GetPostgresType("unknown");
26-
_typeInfoCache = PortableTypeIds ? new TypeInfoCache<DataTypeName>(this) : new TypeInfoCache<Oid>(this);
2726
}
2827

2928
// Represents the 'unknown' type, which can be used for reading and writing arbitrary text values.
@@ -62,8 +61,8 @@ internal bool IntrospectionMode
6261
// for.
6362
PgTypeInfo? GetTypeInfoCore(Type? type, PgTypeId? pgTypeId, bool defaultTypeFallback)
6463
=> PortableTypeIds
65-
? Unsafe.As<TypeInfoCache<DataTypeName>>(_typeInfoCache).GetOrAddInfo(type, pgTypeId?.DataTypeName, defaultTypeFallback)
66-
: Unsafe.As<TypeInfoCache<Oid>>(_typeInfoCache).GetOrAddInfo(type, pgTypeId?.Oid, defaultTypeFallback);
64+
? Unsafe.As<TypeInfoCache<DataTypeName>>(_typeInfoCache ??= new TypeInfoCache<DataTypeName>(this)).GetOrAddInfo(type, pgTypeId?.DataTypeName, defaultTypeFallback)
65+
: Unsafe.As<TypeInfoCache<Oid>>(_typeInfoCache ??= new TypeInfoCache<Oid>(this)).GetOrAddInfo(type, pgTypeId?.Oid, defaultTypeFallback);
6766

6867
public PgTypeInfo? GetDefaultTypeInfo(PostgresType pgType)
6968
=> GetTypeInfoCore(null, ToCanonicalTypeId(pgType), false);

0 commit comments

Comments
 (0)