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

The resource object with key 'TimeSpanHumanize_MultipleWeeks' was not found #1008

Closed
Atulin opened this issue Nov 18, 2020 · 3 comments
Closed

Comments

@Atulin
Copy link

Atulin commented Nov 18, 2020

Versions:

  • ASP.NET 5
  • .NET 5
  • C# 9
  • Humanizer.Core 2.8.26

My code:

public static string UserUnban(OgmaUser user, string modName, DateTime until) 
    => $"User **{user.UserName}** (id: {user.Id}) has been unbanned {(DateTime.Now - until).Humanize(3)} early by **{modName}**.";

with the value of until being DateTime.Now.AddDays(35.0). With until being DateTime.Now.AddDays(3), the exception is TimeSpanHumanize_MultipleDays.

Issue seems to persist even if no precision is given.

Exception:

System.ArgumentException: The resource object with key 'TimeSpanHumanize_MultipleWeeks' was not found (Parameter 'resourceKey')
   at Humanizer.Localisation.Formatters.DefaultFormatter.Format(String resourceKey, Int32 number, Boolean toWords) in /_/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs:line 118
   at Humanizer.Localisation.Formatters.DefaultFormatter.GetResourceForTimeSpan(TimeUnit unit, Int32 count, Boolean toWords) in /_/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs:line 83
   at Humanizer.Localisation.Formatters.DefaultFormatter.TimeSpanHumanize(TimeUnit timeUnit, Int32 unit, Boolean toWords) in /_/src/Humanizer/Localisation/Formatters/DefaultFormatter.cs:line 71
   at Humanizer.TimeSpanHumanizeExtensions.CreateTheTimePartsWithUpperAndLowerLimits(TimeSpan timespan, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, Boolean toWords) in /_/src/Humanizer/TimeSpanHumanizeExtensions.cs:line 63
   at Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan timeSpan, Int32 precision, Boolean countEmptyUnits, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, String collectionSeparator, Boolean toWords) in /_/src/Humanizer/TimeSpanHumanizeExtensions.cs:line 50
   at Humanizer.TimeSpanHumanizeExtensions.Humanize(TimeSpan timeSpan, Int32 precision, CultureInfo culture, TimeUnit maxUnit, TimeUnit minUnit, String collectionSeparator, Boolean toWords) in /_/src/Humanizer/TimeSpanHumanizeExtensions.cs:line 33
   at Ogma3.Data.ModeratorActionTemplates.UserUnban(OgmaUser user, String modName, DateTime until) in G:\VS Projects\Ogma3\Ogma3\Data\ModeratorActionTemplates.cs:line 13
   at Ogma3.Api.V1.UsersController.BanUser(BanData data) in G:\VS Projects\Ogma3\Ogma3\Api\V1\UsersController.cs:line 141
   at lambda_method801(Closure , Object )
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Logged|17_1(ResourceInvoker invoker)
   at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
   at Microsoft.AspNetCore.Authorization.Policy.AuthorizationMiddlewareResultHandler.HandleAsync(RequestDelegate next, HttpContext context, AuthorizationPolicy policy, PolicyAuthorizationResult authorizeResult)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore.MigrationsEndPointMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
@Atulin
Copy link
Author

Atulin commented Nov 18, 2020

Update: deleted my obj and bin directories thinking maybe a clean rebuild and fetching the dependencies again would help, but no cigar.

@Atulin
Copy link
Author

Atulin commented Nov 19, 2020

Solved.

I thought Humanizer uses CultureInfo.InvariantCulture by default, but it seems it tried to use a culture whose dictionary wasn't installed. Specifying the culture explicitly seems to have helped:

(until - DateTime.Now).Humanize(3, culture: CultureInfo.InvariantCulture)

@Atulin Atulin closed this as completed Nov 19, 2020
@hazzik
Copy link
Member

hazzik commented Feb 22, 2024

Duplicate of #690

@hazzik hazzik marked this as a duplicate of #690 Feb 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants