Base solution for your next web application
Open Closed

Exception being thrown by Excel Exporter when using multiple timezones #5805


User avatar
0
gep13 created

Hello,

We are seeing an issue with the default Excel Exporter, for example within the Audit Logs section of the site.

This was working properly, however, now that we have switched to handle multiple timezones, it is causing an exception. Here is what we did...

We added the following code to the Startup.cs class:

Clock.Provider = ClockProviders.Utc;

Now, when we navigate to the Audit Logs section of the site, and click Export to excel, we get "An internal error occurred during your request". Then, digging into the logs we see the following

ERROR 2018-10-19 11:30:38,069 [12 ] Mvc.ExceptionHandling.AbpExceptionFilter - The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone System.ArgumentException: The conversion could not be completed because the supplied DateTime did not have the Kind property set correctly. For example, when the Kind property is DateTimeKind.Local, the source time zone must be TimeZoneInfo.Local. Parameter name: sourceTimeZone at System.TimeZoneInfo.ConvertTime(DateTime dateTime, TimeZoneInfo sourceTimeZone, TimeZoneInfo destinationTimeZone, TimeZoneInfoOptions flags, CachedData cachedData) at Abp.Timing.Timezone.TimezoneHelper.Convert(Nullable1 date, String fromTimeZoneId, String toTimeZoneId) at Abp.Timing.Timezone.TimeZoneConverter.Convert(Nullable1 date, Nullable1 tenantId, Int64 userId) at xxx.xxx.Auditing.Exporting.AuditLogListExcelExporter.<>c__DisplayClass3_0.<ExportToFile>b__1(AuditLogListDto _) at xxx.xxx.DataExporting.Excel.EpPlus.EpPlusExcelExporterBase.AddObjects[T](ExcelWorksheet sheet, Int32 startRowIndex, IList1 items, Func2[] propertySelectors) at xxx.xxx.Auditing.Exporting.AuditLogListExcelExporter.<>c__DisplayClass3_0.<ExportToFile>b__0(ExcelPackage excelPackage) at xxx.xxx.DataExporting.Excel.EpPlus.EpPlusExcelExporterBase.CreateExcelPackage(String fileName, Action1 creator) at xxx.xxx.Auditing.Exporting.AuditLogListExcelExporter.ExportToFile(List`1 auditLogListDtos) at xxx.xxx.Auditing.AuditLogAppService.d__6.MoveNext()

--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at lambda_method(Closure , Object ) at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult() at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__12.MoveNext()

--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__10.MoveNext()

--- End of stack trace from previous location where exception was thrown --- at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Rethrow(ActionExecutedContext context) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.d__14.MoveNext()

--- End of stack trace from previous location where exception was thrown --- at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at Microsoft.AspNetCore.Mvc.Internal.ResourceInvoker.d__23.MoveNext()

If I debug the Exporter when this is happening, I can see that the Kind of one of the dates is correctly (or at least I think it is correctly set) to Utc.

Undoing the code change that was made above, and debugging again when the Exporter is working, I can see that the Kind of one of the DateTime is set to Unspecified.

Can you please advice on how to correct this? Having enabled multiple timezones, are there additional code changes that need to be made? If so, where can I find documentation for this?

Thanks

Gary


7 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Are you using TimeZoneConverter 2.4.1 or above ?

  • User Avatar
    0
    gep13 created

    Naive question...

    How would I know that?

  • User Avatar
    0
    gep13 created

    @ismcagdas Can you provide any additional information in order for me to answer your question? Thanks. I would really like to get to the bottom of this problem.

  • User Avatar
    1
    aaron created
    Support Team

    Are you using TimeZoneConverter 2.4.1 or above ?

    How would I know that?

    Check the NuGet packages in .Core project.

  • User Avatar
    0
    gep13 created

    @aaron @ismcagdas thank you both for your help so far.

    I can confirm that I am currently using TimeZoneConverter 2.3.1. Is the recommendation to be using 2.4.1? Is it as simple as updating this single package? Or are there other packages that I would also need to update?

    Thanks

  • User Avatar
    0
    aaron created
    Support Team

    That should be sufficient.

  • User Avatar
    0
    gep13 created

    @aaron Thank you very much. I am happy to confirm that updating to the latest TimeZoneConverter library (at the time of writing 2.4.2) corrected the problem that I was seeing.