Skip to content

Commit 584bd0c

Browse files
committed
Fix NullReferenceException in .NET Standard.
1 parent 8f05de7 commit 584bd0c

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/MsgPack/ReflectionAbstractions.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,15 @@ public static Type GetAttributeType( this CustomAttributeData source )
411411

412412
public static string GetMemberName( this CustomAttributeNamedArgument source )
413413
{
414+
// This is hack to check null because .NET Standard 1.1 does not expose CustomAttributeNamedArgument.MemberInfo
415+
// but it still throws NullReferenceException when its private MemberInfo type field is null.
416+
// This is caused by default instance of CustomAttributeNamedArgument, so it also should have default CustomAttributeTypedArgument
417+
// which has null ArgumentType.
418+
if ( source.TypedValue.ArgumentType == null )
419+
{
420+
return null;
421+
}
422+
414423
return source.MemberName;
415424
}
416425
#else

0 commit comments

Comments
 (0)