1
votes

I am writing an API using Asp.net Core 3.1. I'm using IHostedService for background processing in the API.

IHostedService class:

    public class DataUpdateBackgroundService : Microsoft.Extensions.Hosting.BackgroundService
    {
        private ITurkeyProvinceDataService _dataService;

        public DataUpdateBackgroundService(ITurkeyProvinceDataService dataService)
        {
            _dataService = dataService;
        }

        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            stoppingToken.Register(() =>
                Console.WriteLine(""));

            while (!stoppingToken.IsCancellationRequested)
            {

                // Your code here
                _dataService.UpdateData();
                await Task.Delay(TimeSpan.FromMinutes(10), stoppingToken);
            }

        }
    }

In my UpdateData function,

I record data in a database for 10 minutes. I am pulling this saved data from a different API.

As such, it works smoothly on my local device.

When I publish this version in Azure Web Service, I get the error in the title. But if I don't use my UpdateData function, I don't get the error.

I could not understand whether it is related to Azure or my function should be in a structure like async. Can you help me with this?

1
@JoeyCai My problem is solved . The reason for this problem stems from var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time"); that i use for date operations in update data functionMuhammet Caylak
I update it in my reply. You can accept it as answer to let others know.Joey Cai

1 Answers

0
votes

This issue occurs because of mixing library references in the project. For example, if you are upgrading your .NET Core 2.2 application to .NET Core 3.1, you should make sure there is no reference or dependency to 2.2 libraries.

I test in my site and work well. Go to your webapp and click Extensions and remove the extension from the App service. And check the nuget package in you local. Here are similar issue you could refer to.

Update:

The reason for this problem stems from var info = TimeZoneInfo.FindSystemTimeZoneById("Turkey Standard Time"); that i use for date operations in update data function.