@@ -91,9 +91,7 @@ internal static MemberTypeInfo Decode(BinaryReader reader, int count, PayloadOpt
91
91
const AllowedRecordTypes SystemClass = Classes | AllowedRecordTypes . SystemClassWithMembersAndTypes
92
92
// All primitive types can be stored by using one of the interfaces they implement.
93
93
// Example: `new IEnumerable[1] { "hello" }` or `new IComparable[1] { int.MaxValue }`.
94
- | AllowedRecordTypes . BinaryObjectString | AllowedRecordTypes . MemberPrimitiveTyped
95
- // System.Nullable<UserStruct> is a special case of SystemClassWithMembersAndTypes
96
- | AllowedRecordTypes . ClassWithMembersAndTypes ;
94
+ | AllowedRecordTypes . BinaryObjectString | AllowedRecordTypes . MemberPrimitiveTyped ;
97
95
const AllowedRecordTypes NonSystemClass = Classes | AllowedRecordTypes . ClassWithMembersAndTypes ;
98
96
99
97
return binaryType switch
@@ -104,10 +102,29 @@ internal static MemberTypeInfo Decode(BinaryReader reader, int count, PayloadOpt
104
102
BinaryType . StringArray => ( StringArray , default ) ,
105
103
BinaryType . PrimitiveArray => ( PrimitiveArray , default ) ,
106
104
BinaryType . Class => ( NonSystemClass , default ) ,
105
+ BinaryType . SystemClass when IsNullableUserTypeRepresentedAsSystemType ( ( TypeName ) additionalInfo ! ) => ( SystemClass | AllowedRecordTypes . ClassWithMembersAndTypes , default ) ,
107
106
BinaryType . SystemClass => ( SystemClass , default ) ,
108
107
BinaryType . ObjectArray => ( ObjectArray , default ) ,
109
108
_ => throw new InvalidOperationException ( )
110
109
} ;
110
+
111
+ static bool IsNullableUserTypeRepresentedAsSystemType ( TypeName typeName )
112
+ {
113
+ if ( ! typeName . IsConstructedGenericType || typeName . Name != typeof ( Nullable < > ) . Name )
114
+ {
115
+ return false ;
116
+ }
117
+
118
+ var genericArgs = typeName . GetGenericArguments ( ) ;
119
+ if ( genericArgs . Length != 1 )
120
+ {
121
+ return false ;
122
+ }
123
+
124
+ // If the generic argument is not from CoreLib, then it is a user type.
125
+ var assemblyName = genericArgs [ 0 ] . AssemblyName ;
126
+ return assemblyName is not null && ! assemblyName . FullName . Equals ( TypeNameHelpers . CoreLibAssemblyName . FullName , StringComparison . Ordinal ) ;
127
+ }
111
128
}
112
129
113
130
internal TypeName GetArrayTypeName ( ArrayInfo arrayInfo )
0 commit comments