From dbcfd2f9d18a595757194202de518b62ae9eb9f7 Mon Sep 17 00:00:00 2001 From: stakx Date: Mon, 7 May 2018 18:28:37 +0200 Subject: Reflection: Fix DefaultValue for optional DateTime (#17877) 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. --- src/mscorlib/src/System/Reflection/MdConstant.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/mscorlib/src/System/Reflection/MdConstant.cs b/src/mscorlib/src/System/Reflection/MdConstant.cs index 8e5b65724d..7337039908 100644 --- a/src/mscorlib/src/System/Reflection/MdConstant.cs +++ b/src/mscorlib/src/System/Reflection/MdConstant.cs @@ -94,6 +94,9 @@ namespace System.Reflection defaultValue = buffer; break; + case CorElementType.Class: + return null; + default: throw new FormatException(SR.Arg_BadLiteralFormat); #endregion -- cgit v1.2.3