-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ParameterInfo.HasDefaultValue throws System.FormatException on optional DateTime parameter #18844
Comments
@sepidehms do you think you can have a look at this issue? I feel that these tests should be updated to include also the |
@justinvp would you like to update the |
Is the described behavior from desktop .NET Framework? Or just general desire? |
I have also run into this on .NET Core. The The only way I see to avoid it is having my reflection code step around DateTime parameters. private static object GetDefaultValue(ParameterInfo parameter) {
return parameter.ParameterType == typeof(DateTime) ? default(DateTime) : parameter.DefaultValue
}
var defaultValues =
typeof(Foo)
.GetConstructors()[0]
.GetParameters()
.Select(GetDefaultValue)
.ToList(); |
|
@karelz in my case, I want this to work both on the .NET Framework and on .NET Core. |
Looks related to #18599 Next step: Root-cause (under debugger) and propose a fix. |
dotnet/corefx#17943 dotnet/corefx#12338 dotnet/corefx#11797
@steveharter Given dotnet/coreclr#17877 has been merged for quite some time now and the titular bug does not repro on .NET Core 3.1, maybe it is time to close this issue and remove it from the reflection roadmap for 5.0? |
I'm going to resolve based on comment above. |
I'm going to resolve based on comment above. |
When accessing
ParameterInfo.HasDefaultValue
for a parameter of typeSystem.DateTime
, Iget an unexpected
System.FormatException
.ParameterInfo.Attributes
is correctly set toOptional | HasDefault
.If the parameter is of any other value type (e.g.
decimal
or some custom struct) theproperty works as expected. There is something specific to
DateTime
in the implementationof
RuntimeParameterInfo.GetDefaultValueInternal()
which is broken.Code snippet to test:
Exception:
The text was updated successfully, but these errors were encountered: