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

1k Views Asked by At

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"
            }
        }
    }
}
3

There are 3 best solutions below

0
On BEST ANSWER

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!

1
On

When I have created Azure Function .NET 7.0 Isolated,below packages are included by default.

<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.14.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.10.0" />

Initially even I got the same error when I tried to run with your .csproj package versions.

enter image description here

  • Check the logs in Azure Function App => Log stream => Filesystem Logs

enter image description here

The configuration file 'local.settings.json' was not found and is not optional. The expected physical path was 'C:\home\site\wwwroot\local.settings.json'.

There seems to be an issue with the below line of code.

.AddJsonFile("local.settings.json", false, true)

Change the code as below.

.AddJsonFile("local.settings.json", optional: true, reloadOnChange: false)
  • Build and Re-publish the App again.

Now, Iam able to run the deployed Azure Function without any issues.

My .csproj file:

 <ItemGroup>
    <None Update="host.json">
      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
    </None>
    <None Update="local.settings.json">
      <CopyToOutputDirectory>Always</CopyToOutputDirectory>
      <CopyToPublishDirectory>Never</CopyToPublishDirectory>
    </None>
  </ItemGroup>

Log stream:

enter image description here

Output:

enter image description here

0
On

Same behavior for me. The reason is explicit, dotnet 7 is not available on my linux function. Only 3.1 and 6.0 are.enter image description here

Thanks to Terraform, just detroy and recreate the ressources with replacing os_type = Linux by os_type = Windows on the Azure Service Plan and everything works great.

resource "azurerm_service_plan" "sp" {
  name                = "XXXXXXXXXXXXXXX-sp"
  location            = azurerm_resource_group.rg.location
  resource_group_name = azurerm_resource_group.rg.name
  os_type             = "Windows"
  # Y1 is an as-you-go consumption plan
  sku_name            = "Y1"
}

Note that my code was successfully executed on my local Linux environnement, and I've changed nothing else than the os_type of the SP.