Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Reflection: Fix DefaultValue for optional DateTime (#17877)
Browse files Browse the repository at this point in the history
Querying the default value of an optional `DateTime` parameter using
`ParameterInfo.DefaultValue` can throw a `FormatException` if that
default value is a null constant in metadata, which is how the C#
compiler encodes a default value of `default(DateTime)`.

This commit fixes that error by adding the proper handling for null
metadata constants with `DateTime` parameters.
  • Loading branch information
stakx authored and atsushikan committed May 7, 2018
1 parent fceac03 commit dbcfd2f
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/mscorlib/src/System/Reflection/MdConstant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ public static unsafe Object GetValue(MetadataImport scope, int token, RuntimeTyp
defaultValue = buffer;
break;

case CorElementType.Class:
return null;

default:
throw new FormatException(SR.Arg_BadLiteralFormat);
#endregion
Expand Down

0 comments on commit dbcfd2f

Please sign in to comment.