Skip to content
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

TimeOnly is not read from appsettings #64739

Closed
1 task done
wertzui opened this issue Feb 3, 2022 · 2 comments
Closed
1 task done

TimeOnly is not read from appsettings #64739

wertzui opened this issue Feb 3, 2022 · 2 comments
Labels
area-Extensions-Configuration untriaged New issue has not been triaged by the area owner

Comments

@wertzui
Copy link

wertzui commented Feb 3, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Having an appsettings.json that looks like this

{
    "MyTime": "01:02"
}

When trying to bind this to a TimeOnly, the result is always an Exception (or 00:00 depending on how it is read), while the result is 01:02 when binding to a TimeSpan.

Expected Behavior

The value can be bound to a TimeOnly instance.

Steps To Reproduce

configuration.GetValue<TimeSpan>("MyTime"); // 01:02
configuration.GetValue<TimeOnly>("MyTime"); // System.NullReferenceException
configuration.GetSection("MyTime").Get<TimeOnly>(); // 00:00

Exceptions (if any)

It is a System.NullReferenceException

Stack trace for the Exception:

at System.Runtime.CompilerServices.CastHelpers.Unbox(Void* toTypeHnd, Object obj)
at Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue[T](IConfiguration configuration, String key, T defaultValue)
at Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue[T](IConfiguration configuration, String key)

.NET Version

6.0.200-preview.21617.4

Anything else?

No response

@javiercn javiercn transferred this issue from dotnet/aspnetcore Feb 3, 2022
@dotnet-issue-labeler dotnet-issue-labeler bot added area-Extensions-Configuration untriaged New issue has not been triaged by the area owner labels Feb 3, 2022
@ghost
Copy link

ghost commented Feb 3, 2022

Tagging subscribers to this area: @dotnet/area-extensions-configuration
See info in area-owners.md if you want to be subscribed.

Issue Details

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Having an appsettings.json that looks like this

{
    "MyTime": "01:02"
}

When trying to bind this to a TimeOnly, the result is always an Exception (or 00:00 depending on how it is read), while the result is 01:02 when binding to a TimeSpan.

Expected Behavior

The value can be bound to a TimeOnly instance.

Steps To Reproduce

configuration.GetValue<TimeSpan>("MyTime"); // 01:02
configuration.GetValue<TimeOnly>("MyTime"); // System.NullReferenceException
configuration.GetSection("MyTime").Get<TimeOnly>(); // 00:00

Exceptions (if any)

It is a System.NullReferenceException

Stack trace for the Exception:

at System.Runtime.CompilerServices.CastHelpers.Unbox(Void* toTypeHnd, Object obj)
at Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue[T](IConfiguration configuration, String key, T defaultValue)
at Microsoft.Extensions.Configuration.ConfigurationBinder.GetValue[T](IConfiguration configuration, String key)

.NET Version

6.0.200-preview.21617.4

Anything else?

No response

Author: wertzui
Assignees: -
Labels:

untriaged, area-Extensions-Configuration

Milestone: -

@tarekgh
Copy link
Member

tarekgh commented Feb 3, 2022

@wertzui Thanks for your report. This is a duplicate of #59253.

@tarekgh tarekgh closed this as completed Feb 3, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Extensions-Configuration untriaged New issue has not been triaged by the area owner
Projects
None yet
Development

No branches or pull requests

3 participants