abpframework / abp

Open-source web application framework for ASP.NET Core! Offers an opinionated architecture to build enterprise software solutions with best practices on top of the .NET. Provides the fundamental infrastructure, cross-cutting-concern implementations, startup templates, application modules, UI themes, tooling and documentation.
https://abp.io
GNU Lesser General Public License v3.0
12.87k stars 3.43k forks source link

Localization exception `System.Globalization.PersianCalendar` #12586

Closed mheidari988 closed 2 years ago

mheidari988 commented 2 years ago

First I Added fa localization by using abp translate -c fa which generated json file to translate. Then after full translation and using abp translate -a command, the application had fa language in the menu. When I changed the language to the farsi and tried to open the CreateModal page, the application throws the exception.

Note that there is not any exception in other languages.

This occurs when

[21:49:10 INF] Executing endpoint '/Persons/CreateModal'
[21:49:11 INF] Route matched with {page = "/Persons/CreateModal", area = "", action = "", controller = ""}. Executing page /Persons/CreateModal
[21:49:11 INF] Skipping the execution of current filter as its not the most effective filter implementing the policy Microsoft.AspNetCore.Mvc.ViewFeatures.IAntiforgeryPolicy
[21:49:11 INF] Executing handler method Mat.Crm.Web.Pages.Persons.CreateModalModel.OnGet - ModelState is Valid
[21:49:11 INF] Executed handler method OnGet, returned result .
[21:49:11 INF] Executing an implicit handler method - ModelState is Valid
[21:49:11 INF] Executed an implicit handler method, returned result Microsoft.AspNetCore.Mvc.RazorPages.PageResult.
[21:49:11 INF] Executed page /Persons/CreateModal in 123.1883ms
[21:49:11 INF] Executed endpoint '/Persons/CreateModal'
[21:49:11 DBG] Added 0 entity changes to the current audit log
[21:49:11 DBG] Added 0 entity changes to the current audit log
[21:49:11 ERR] An unhandled exception has occurred while executing the request.
System.ArgumentOutOfRangeException: Specified time is not supported in this calendar. It should be between 0001/1/1 0:00:00 (Gregorian date) and 9378/10/13 23:59:59 (Gregorian date), inclusive. (Parameter 'time')
Actual value was 0.
   at System.Globalization.PersianCalendar.CheckTicksRange(Int64 ticks)
   at System.Globalization.PersianCalendar.GetDatePart(Int64 ticks, Int32 part)
   at System.Globalization.PersianCalendar.GetYear(DateTime time)
   at System.DateTimeFormat.FormatCustomized(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset, StringBuilder result)
   at System.DateTimeFormat.FormatStringBuilder(DateTime dateTime, ReadOnlySpan`1 format, DateTimeFormatInfo dtfi, TimeSpan offset)
   at System.DateTimeFormat.TryFormat(DateTime dateTime, Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider, TimeSpan offset)
   at System.DateTime.TryFormat(Span`1 destination, Int32& charsWritten, ReadOnlySpan`1 format, IFormatProvider provider)
   at System.Text.ValueStringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)
   at System.String.Format(IFormatProvider provider, String format, Object arg0)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewDataDictionary.FormatValue(Object value, String format)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateInput(ViewContext viewContext, InputType inputType, ModelExplorer modelExplorer, String expression, Object value, Boolean useViewData, Boolean isChecked, Boolean setId, Boolean isExplicitValue, String format, IDictionary`2 htmlAttributes)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.DefaultHtmlGenerator.GenerateTextBox(ViewContext viewContext, ModelExplorer modelExplorer, String expression, Object value, String format, Object htmlAttributes)
   at Microsoft.AspNetCore.Mvc.TagHelpers.InputTagHelper.GenerateTextBox(ModelExplorer modelExplorer, String inputTypeHint, String inputType, IDictionary`2 htmlAttributes)
   at Microsoft.AspNetCore.Mvc.TagHelpers.InputTagHelper.Process(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.TagHelpers.TagHelper.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions.TagHelperExtensions.ProcessAndGetOutputAsync(TagHelper tagHelper, TagHelperAttributeList attributeList, TagHelperContext context, String tagName, TagMode tagMode)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpInputTagHelperService.GetInputTagHelperOutputAsync(TagHelperContext context, TagHelperOutput output)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpInputTagHelperService.GetFormInputGroupAsHtmlAsync(TagHelperContext context, TagHelperOutput output)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpInputTagHelperService.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions.TagHelperExtensions.ProcessAndGetOutputAsync(TagHelper tagHelper, TagHelperAttributeList attributeList, TagHelperContext context, String tagName, TagMode tagMode)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Extensions.TagHelperExtensions.RenderAsync(TagHelper tagHelper, TagHelperAttributeList attributeList, TagHelperContext context, HtmlEncoder htmlEncoder, String tagName, TagMode tagMode)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpDynamicFormTagHelperService.ProcessInputGroupAsync(TagHelperContext context, TagHelperOutput output, ModelExpression model)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpDynamicFormTagHelperService.ProcessFieldsAsync(TagHelperContext context, TagHelperOutput output)
   at Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Form.AbpDynamicFormTagHelperService.ProcessAsync(TagHelperContext context, TagHelperOutput output)
   at Microsoft.AspNetCore.Razor.Runtime.TagHelpers.TagHelperRunner.<RunAsync>g__Awaited|0_0(Task task, TagHelperExecutionContext executionContext, Int32 i, Int32 count)
   at AspNetCore._Pages_Persons_CreateModal.ExecuteAsync() in D:\msrc\CrmRepo\src\Mat.Crm.Web\Pages\Persons\CreateModal.cshtml:line 11
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageCoreAsync(IRazorPage page, ViewContext context)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderPageAsync(IRazorPage page, ViewContext context, Boolean invokeViewStarts)
   at Microsoft.AspNetCore.Mvc.Razor.RazorView.RenderAsync(ViewContext context)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.ViewFeatures.ViewExecutor.ExecuteAsync(ViewContext viewContext, String contentType, Nullable`1 statusCode)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResultFilterAsync>g__Awaited|30_0[TFilter,TFilterAsync](ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResultExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.ResultNext[TFilter,TFilterAsync](State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeResultFilters>g__Awaited|28_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|25_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|20_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.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 Volo.Abp.AspNetCore.Serilog.AbpSerilogMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Volo.Abp.AspNetCore.Auditing.AbpAuditingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
   at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
   at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.IdentityServerMiddleware.Invoke(HttpContext context, IEndpointRouter router, IUserSession session, IEventService events, IBackChannelLogoutService backChannelLogoutService)
   at IdentityServer4.Hosting.MutualTlsEndpointMiddleware.Invoke(HttpContext context, IAuthenticationSchemeProvider schemes)
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at IdentityServer4.Hosting.BaseUrlMiddleware.Invoke(HttpContext context)
   at Volo.Abp.AspNetCore.Uow.AbpUnitOfWorkMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Volo.Abp.AspNetCore.ExceptionHandling.AbpExceptionHandlingMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Volo.Abp.AspNetCore.MultiTenancy.MultiTenancyMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Builder.ApplicationBuilderAbpJwtTokenMiddlewareExtension.<>c__DisplayClass0_0.<<UseJwtTokenMiddleware>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context)
   at Volo.Abp.AspNetCore.Tracing.AbpCorrelationIdMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Localization.RequestLocalizationMiddleware.Invoke(HttpContext context)
   at Microsoft.AspNetCore.RequestLocalization.AbpRequestLocalizationMiddleware.InvokeAsync(HttpContext context, RequestDelegate next)
   at Microsoft.AspNetCore.Builder.UseMiddlewareExtensions.<>c__DisplayClass6_1.<<UseMiddlewareInterface>b__1>d.MoveNext()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
[21:49:11 INF] Request finished HTTP/2 GET https://localhost:44337/Persons/CreateModal - - - 500 - text/html;+charset=utf-8 1048.1877ms
maliming commented 2 years ago

System.ArgumentOutOfRangeException: Specified time is not supported in this calendar. It should be between 0001/1/1 0:00:00 (Gregorian date) and 9378/10/13 23:59:59 (Gregorian date), inclusive. (Parameter 'time') Actual value was 0.

Hi

Please check the datetime properties in your model.

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

ParsaGachkar commented 2 years ago

It's because negative values are not supported in DateTime. 0001/01/01 (Default DateTime) in Gregorian Calendar will map to a negative year in Persian Calendar. I'm almost 100% sure that there are better ways to Handle this issue. but here is a quick fix just use new CultureInfo("fa-ir").Calendar.MinSupportedDateTime; instead of default or DateTime.Min + initialize datetime values to corresponding value of MinSupportedDateTime for your calendar (in our case Persian Calendar) and you should be fine.