Search code examples
c#azure-functionsazure-functions-runtimedotnet-isolatedazure-functions-isolated

Failed to start a new language worker for runtime: dotnet-isolated - latest version of C# .Net 7


I have an Isolated Azure Function. Now I am getting this famous error:

Failed to start a new language worker for runtime: dotnet-isolated

I have searched and done all possible solutions in Stack overflow and Github. The reason I am asking is most of the answers where about more than 3-4 months ago. I am wondering there would be any progress about it in latest versions? (or maybe I should downgrade to any specific version.)

It runs fine in my local but the problem appears after publishing.

I am using the latest version of .Net (.net 7) and Function Worker 1.16.0. All of my NuGet Packages are uptodate. My Azure Runtime version is 4.22.0.20804. And yes I have set FUNCTIONS_WORKER_RUNTIME to dotnet-isolated. In my Program.cs I already have added .ConfigureFunctionsWorkerDefaults()

this is my project setting:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <RootNamespace>cg_sfsc</RootNamespace>
        <OutputType>Exe</OutputType>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.15.0" />
        <PackageReference Include="Azure.Storage.Blobs" Version="12.16.0" />
        <PackageReference Include="Azure.Storage.Files.Shares" Version="12.14.0" />
        <PackageReference Include="Azure.Storage.Queues" Version="12.14.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.16.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="5.11.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.11.0" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
        <PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="5.1.2" />
        <PackageReference Include="Microsoft.Extensions.Azure" Version="1.6.3" />
        <PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="7.0.0" />
        <PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="7.0.0" />
        <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
        <PackageReference Include="Polly" Version="7.2.4" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>Always</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
</Project>

Any Idea what else should I do?

This is my Progam.cs :

public class Program
{
    public static async Task Main(string[] args)
    {
        var host = new HostBuilder()
    .ConfigureFunctionsWorkerDefaults()
     .ConfigureAppConfiguration(config =>
     {
         config.SetBasePath(Directory.GetCurrentDirectory())
             .AddJsonFile("local.settings.json", false, true)
             .AddEnvironmentVariables();
     })
     .ConfigureServices((context, services) =>
     {
         var configurationRoot = context.Configuration;
         services.Configure<IVSOptions>(configurationRoot.GetSection(nameof(IVSOptions)));


         services.AddSingleton<ICacheProvider, DistributedCacheProvider>();
         services.AddStackExchangeRedisCache(option =>
         {
             option.Configuration = configurationRoot.GetConnectionString("RedisCache");
         });


         services.AddHttpClient();
         services.AddLogging();

         services.AddScoped<IInventoryRepository, InventoryRepository>();

     })

    .Build();

        await host.RunAsync();

    }
}

and this is my host.json :

{
    "version": "2.0",
    "logging": {
        "applicationInsights": {
            "samplingSettings": {
                "isEnabled": true,
                "excludedTypes": "Request"
            }
        }
    }
}

Solution

  • My problem was so strange; I was running two Azure functions in same class: This was my Not Working code:

     public class InventorySyncFunctions
        {
            private readonly IInventorySyncService _service;
            private readonly ILogger _logger;
    
            public InventorySyncFunctions(IInventorySyncService service, ILogger<InventorySyncOnDemand> logger)
            {
                _service = service;
                _logger = logger;
            }
    
            [Function("InventorySyncOnDemand")]
            public async Task InventorySyncOnDemand([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, CancellationToken cancellationToken)
            {
                _logger.LogInformation($"InventorySyncOnDemand executed at: {DateTime.UtcNow} UTC");
    
                await _service.PerformInventorySyncExecute(cancellationToken);
            }
    
            [Function("InventorySyncTimerTrigger")]
            public async Task InventorySyncTimerTrigger([TimerTrigger("%InventorySyncCronTime%")] TimerInfo myTimer, CancellationToken cancellationToken)
            {
                _logger.LogInformation($"InventorySyncTimerTrigger executed at: {DateTime.UtcNow} UTC");
    
                await _service.PerformInventorySyncExecute(cancellationToken);
            }
    
        }
    

    however, I found I have to separate the Azure Functions and call them "Run". So Now I have two different classes:

    public class InventorySyncOnDemand
        {
            private readonly IInventorySyncService _service;
            private readonly ILogger _logger;
    
            public InventorySyncOnDemand(IInventorySyncService service, ILogger<InventorySyncOnDemand> logger)
            {
                _service = service;
                _logger = logger;
            }
    
            [Function("InventorySyncOnDemand")]
            public async Task Run([HttpTrigger(AuthorizationLevel.Function, "get", "post")] HttpRequestData req, CancellationToken cancellationToken)
            {
                _logger.LogInformation($"InventorySyncOnDemand executed at: {DateTime.UtcNow} UTC");
    
                await _service.PerformInventorySyncExecute(cancellationToken);
            }
        }
    

    And

     public class InventorySyncTimerTrigger
        {
            private readonly IInventorySyncService _service;
            private readonly ILogger _logger;
        
             public InventorySyncTimerTrigger(IInventorySyncService service, ILogger<InventorySyncTimerTrigger> logger)
            {
                _service = service;
                _logger = logger;
            }
        
            [Function("InventorySyncTimerTrigger")]
            public async Task Run([TimerTrigger("%InventorySyncCronTime%")] TimerInfo myTimer, CancellationToken cancellationToken)
            {
                _logger.LogInformation($"InventorySyncTimerTrigger executed at: {DateTime.UtcNow} UTC");
        
                await _service.PerformInventorySyncExecute(cancellationToken);
            }
        }
    

    it worked!