@@ -269,7 +269,6 @@ public override void WriteData(TraceLoggingDataCollector collector, PropertyValu
269269 internal sealed class NullableTypeInfo : TraceLoggingTypeInfo
270270 {
271271 private readonly TraceLoggingTypeInfo valueInfo ;
272- private readonly Func < PropertyValue , PropertyValue > hasValueGetter ;
273272 private readonly Func < PropertyValue , PropertyValue > valueGetter ;
274273
275274 public NullableTypeInfo ( Type type , List < Type > recursionCheck )
@@ -278,7 +277,6 @@ public NullableTypeInfo(Type type, List<Type> recursionCheck)
278277 var typeArgs = type . GenericTypeArguments ;
279278 Debug . Assert ( typeArgs . Length == 1 ) ;
280279 this . valueInfo = TraceLoggingTypeInfo . GetInstance ( typeArgs [ 0 ] , recursionCheck ) ;
281- this . hasValueGetter = PropertyValue . GetPropertyGetter ( type . GetTypeInfo ( ) . GetDeclaredProperty ( "HasValue" ) ) ;
282280 this . valueGetter = PropertyValue . GetPropertyGetter ( type . GetTypeInfo ( ) . GetDeclaredProperty ( "Value" ) ) ;
283281 }
284282
@@ -294,9 +292,11 @@ public override void WriteMetadata(
294292
295293 public override void WriteData ( TraceLoggingDataCollector collector , PropertyValue value )
296294 {
297- var hasValue = hasValueGetter ( value ) ;
295+ // It's not currently possible to get the HasValue property of a nullable type through reflection when the
296+ // value is null. Instead, we simply check that the nullable is not null.
297+ var hasValue = value . ReferenceValue != null ;
298298 collector . AddScalar ( hasValue ) ;
299- var val = hasValue . ScalarValue . AsBoolean ? valueGetter ( value ) : valueInfo . PropertyValueFactory ( Activator . CreateInstance ( valueInfo . DataType ) ) ;
299+ var val = hasValue ? valueGetter ( value ) : valueInfo . PropertyValueFactory ( Activator . CreateInstance ( valueInfo . DataType ) ) ;
300300 this . valueInfo . WriteData ( collector , val ) ;
301301 }
302302 }
0 commit comments