Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

Unable to retrieve Timezones from the backend #4951


User avatar
0
cpadmin created

It gives <span style="color:#FF0000">internal server error (500)</span> from

TimezoneHelper.GetWindowsTimeZoneInfos()

function under

GetWindowsTimezones()

in TimeZoneService.cs class.

Please help me with this.


19 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    Hi,

    You have to update your ABP packages. In ABP Abp.Timing.Timezone.TimezoneHelper class fixed. And in AspNet Zero TimingAppService and TimeZoneService is fixed.

    See the GitHub issue: <a class="postlink" href="https://github.com/aspnetboilerplate/aspnetboilerplate/issues/3223">https://github.com/aspnetboilerplate/as ... ssues/3223</a>

  • User Avatar
    0
    cpadmin created

    Could you please be specific about the packages to be updated and the version.

    I upgraded TimeZoneCoverter to 2.3.2, as mentioned in the github issue, but it did not resolve the error I am getting.

  • User Avatar
    0
    ismcagdas created
    Support Team

    @cpadmin,

    Updating nuget packages (all ABP packages to 3.5 and TimeZoneCoverter to 2.3.2) might not solve your problem. Can you share your existing ABP nuget package version and AspNet Zero version ?

    Thanks.

  • User Avatar
    0
    cpadmin created

    Hi,

    ABP version:<span style="color:#40BF80"> 3.4.0</span> AspNet Zero version: <span style="color:#40BF40">5.1.0</span>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Then, probably I think your problem is related to <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/issues/903">https://github.com/aspnetzero/aspnet-ze ... issues/903</a>. Can you try to apply the fix ?

  • User Avatar
    0
    cpadmin created

    I am sorry but the link seems to be broken. It says <span style="color:#FF0040">404 not found</span>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Please add your github username on "Github Users" tab in this page <a class="postlink" href="https://aspnetzero.com/LicenseManagement">https://aspnetzero.com/LicenseManagement</a>. Then accept github invitation and try to visit the link again.

    If you don't receive an invitation email from github, please visit below address to accept invitation <a class="postlink" href="https://github.com/orgs/aspnetzero">https://github.com/orgs/aspnetzero</a>.

  • User Avatar
    0
    cpadmin created

    Hi, By looking into the resolution of the issue, mentioned by you, I can deduce that the definition of the GetWindowsTimezones method, in my version of ABP, is up-to-date:

    public List<NameValueDto> GetWindowsTimezones()
    {
          return TimezoneHelper.GetWindowsTimeZoneInfos().OrderBy(tz => tz.BaseUtcOffset)
                    .Select(tz => new NameValueDto
                    {
                        Value = tz.Id,
                        Name = tz.DisplayName
                    }).ToList();
     }
    

    I can also see that the lodger of the thread was able to retrieve Timezones even when he was using -version 5.0.0. Then what could possibly go wrong in my version of ABP and ASP.NET Zero?

  • User Avatar
    0
    cpadmin created

    It has to do something with TimingAppService as I can see from the Audit Log.

    The log says:

    System.InvalidTimeZoneException: "Aleutian Standard Time" was not recognized as a valid IANA time zone name, or has no equivalant Windows time zone.

    What to do now?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @cpadmin,

    Can you share your project via email ? It will be easier to check it like that.

    Thanks.

  • User Avatar
    0
    cpadmin created

    I am very sorry but I cannot share the project with you as it is client's property. But if you want I can share you the Audit logs related to Timezone.

  • User Avatar
    0
    ismcagdas created
    Support Team

    No problem. Can you share TimingAppService.cs and TimeZoneService.cs ?

  • User Avatar
    0
    cpadmin created

    TimeZoneService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Abp.Application.Services.Dto;
    using Abp.Configuration;
    using Abp.Dependency;
    using Abp.Timing;
    using Abp.Timing.Timezone;
    using TimeZoneConverter;
    
    namespace PhoneBook.PhoneBookProjects_Demo.Timing
    {
        public class TimeZoneService : ITimeZoneService, ITransientDependency
        {
            readonly ISettingManager _settingManager;
            readonly ISettingDefinitionManager _settingDefinitionManager;
    
            public TimeZoneService(
                ISettingManager settingManager,
                ISettingDefinitionManager settingDefinitionManager)
            {
                _settingManager = settingManager;
                _settingDefinitionManager = settingDefinitionManager;
            }
    
            public async Task<string> GetDefaultTimezoneAsync(SettingScopes scope, int? tenantId)
            {
                if (scope == SettingScopes.User)
                {
                    if (tenantId.HasValue)
                    {
                        return await _settingManager.GetSettingValueForTenantAsync(TimingSettingNames.TimeZone, tenantId.Value);
                    }
    
                    return await _settingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone);
                }
    
                if (scope == SettingScopes.Tenant)
                {
                    return await _settingManager.GetSettingValueForApplicationAsync(TimingSettingNames.TimeZone);
                }
    
                if (scope == SettingScopes.Application)
                {
                    var timezoneSettingDefinition = _settingDefinitionManager.GetSettingDefinition(TimingSettingNames.TimeZone);
                    return timezoneSettingDefinition.DefaultValue;
                }
    
                throw new Exception("Unknown scope for default timezone setting.");
            }
    
            public List<NameValueDto> GetWindowsTimezones()
            {
                return TimezoneHelper.GetWindowsTimeZoneInfos().OrderBy(tz => tz.BaseUtcOffset)
                    .Select(tz => new NameValueDto
                    {
                        Value = tz.Id,
                        Name = tz.DisplayName
                    }).ToList();
            }
        }
    }
    

    TimingAppService.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Threading.Tasks;
    using Abp.Application.Services.Dto;
    using Abp.Configuration;
    using PhoneBook.PhoneBookProjects_Demo.Timing.Dto;
    
    namespace PhoneBook.PhoneBookProjects_Demo.Timing
    {
        public class TimingAppService : PhoneBookProjects_DemoAppServiceBase, ITimingAppService
        {
            private readonly ITimeZoneService _timeZoneService;
    
            public TimingAppService(ITimeZoneService timeZoneService)
            {
                _timeZoneService = timeZoneService;
            }
    
            public async Task<ListResultDto<NameValueDto>> GetTimezones(GetTimezonesInput input)
            {
                var timeZones = await GetTimezoneInfos(input.DefaultTimezoneScope);
                return new ListResultDto<NameValueDto>(timeZones);
            }
    
            public async Task<List<ComboboxItemDto>> GetTimezoneComboboxItems(GetTimezoneComboboxItemsInput input)
            {
                var timeZones = await GetTimezoneInfos(input.DefaultTimezoneScope);
                var timeZoneItems = new ListResultDto<ComboboxItemDto>(timeZones.Select(e => new ComboboxItemDto(e.Value, e.Name)).ToList()).Items.ToList();
    
                if (!string.IsNullOrEmpty(input.SelectedTimezoneId))
                {
                    var selectedEdition = timeZoneItems.FirstOrDefault(e => e.Value == input.SelectedTimezoneId);
                    if (selectedEdition != null)
                    {
                        selectedEdition.IsSelected = true;
                    }
                }
    
                return timeZoneItems;
            }
    
            private async Task<List<NameValueDto>> GetTimezoneInfos(SettingScopes defaultTimezoneScope)
            {
                var defaultTimezoneId = await _timeZoneService.GetDefaultTimezoneAsync(defaultTimezoneScope, AbpSession.TenantId);
                var defaultTimezone = TimeZoneInfo.FindSystemTimeZoneById(defaultTimezoneId);
                var defaultTimezoneName = $"{L("Default")} [{defaultTimezone.DisplayName}]";
    
                var timeZones = _timeZoneService.GetWindowsTimezones();
    
                timeZones.Insert(0, new NameValueDto(defaultTimezoneName, string.Empty));
                return timeZones;
            }
        }
    }
    
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    In TimingAppService.cs, there is a line;

    var defaultTimezone = TimeZoneInfo.FindSystemTimeZoneById(defaultTimezoneId);
    

    You need to change it to;

    var defaultTimezone = _timeZoneService.FindTimeZoneById(defaultTimezoneId);
    
  • User Avatar
    0
    cpadmin created

    It says: <span style="color:#FF0000">'ITimeZoneService' does not contain a definition for 'FindTimeZoneById'</span>

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    Here is the ITimeZoneService's latest version <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Timing/ITimeZoneService.cs">https://github.com/aspnetzero/aspnet-ze ... Service.cs</a>

    and here is the TimeZoneService's latest version <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-core/blob/dev/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Timing/TimeZoneService.cs">https://github.com/aspnetzero/aspnet-ze ... Service.cs</a>

    Please add the related method to your interface and it's implementation

  • User Avatar
    0
    cpadmin created

    Even after making the given changes I am still getting the same error: <span style="color:#FF0000">System.InvalidTimeZoneException: "Aleutian Standard Time" was not recognized as a valid IANA time zone name, or has no equivalant Windows time zone.</span>

  • User Avatar
    0
    cangunaydin created

    Hello, I had the similar issue. is your windows up to date it happened to me when I turn off the windows updates maybe that can be the problem ?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @cpadmin, are there any records on your AbpSettings table with the value of "Aleutian Standard Time" ? If not, we can arrange a remote meeting to solve your problem for the next week.