Azure Function App - Failed to start a new language worker for runtime: dotnet-isolated
insights Stats
Data analytics, application development with Microsoft Azure cloud platform.
When building Azure Function App with docker to host in Azure Container App environment, you may encounter an special error when building it with the latest .NET 8 RC 1 release: Failed to start a new language worker for runtime: dotnet-isolated, Microsoft.Azure.WebJobs.Script.Grpc: The operation has timed out.
Root cause
This issue occurs because the base image of Azure Functions Dotnet (Isolated) doesn't contain the required runtime.
For example, assuming you are building Azure Function with latest .NET 8 SDK as at 2023-09-27:
{
"sdk": {
"version": "8.0.100-rc.1.23455.8",
"rollForward": "latestFeature",
"allowPrerelease": true
}
}
Then you build your Azure function using the following Dockerfile:
#See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-dotnet-isolated8.0 AS base
WORKDIR /home/site/wwwroot
EXPOSE 8080
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["src/MyAzureFunctions.csproj", "src/MyAzureFunctions/"]
COPY . .
WORKDIR "/src/src/MyAzureFunctions"
RUN dotnet build "MyAzureFunctions.csproj" -c $BUILD_CONFIGURATION -o /app/build
FROM build AS publish
RUN dotnet publish "MyAzureFunctions.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /home/site/wwwroot
COPY --from=publish /app/publish .
ENV AzureWebJobsScriptRoot=/home/site/wwwroot \
AzureFunctionsJobHost__Logging__Console__IsEnabled=true
When you start the container or when you deploy it to Azure, you will see the error mentioned earlier.
Debug
The root cause can be found in the detailed error logs:
2023-09-23 13:52:18 info: Host.Function.Console[0]
2023-09-23 13:52:18 Framework: 'Microsoft.NETCore.App', version '8.0.0-rc.1.23419.4' (x64)
2023-09-23 13:52:18 info: Host.Function.Console[0]
2023-09-23 13:52:18 .NET location: /usr/share/dotnet/
2023-09-23 13:52:18 info: Host.Function.Console[0]
2023-09-23 13:52:18 info: Host.Function.Console[0]
2023-09-23 13:52:18 The following frameworks were found:
2023-09-23 13:52:18 info: Host.Function.Console[0]
2023-09-23 13:52:18 8.0.0-preview.7.23375.6 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
It basically required .NET 8 RC 1 runtime while only the preview 7 version is available in the base image.
We can also double confirm this by using command line tool:
docker run -it --entrypoint /bin/sh MyAzureFunctions
*Assuming the local built image is named MyAzureFunctions
.
And then run the following command line in the interactive:
# dotnet --list-runtimes
The output looks like the following:
Microsoft.AspNetCore.App 8.0.0-preview.7.23375.9 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0-preview.7.23375.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
This indicates that you can only use .NET 8 preview 7 for your Azure Function App.
Resolution
After looking into the available tags of the base image: https://mcr.microsoft.com/en-us/product/azure-functions/dotnet-isolated/tags, I found tag 4-nightly-dotnet-isolated8.0
does include the .NET 8 RC1 runtime.
Hence, to resolve this issue, we just need to update the base image to the following:
FROM mcr.microsoft.com/azure-functions/dotnet-isolated:4-nightly-dotnet-isolated8.0 AS base
After the new image is built, we can verify it by running the Terminal with the container:
# dotnet --list-runtimes
Microsoft.AspNetCore.App 8.0.0-rc.1.23421.29 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0-rc.1.23419.4[/usr/share/dotnet/shared/Microsoft.NETCore.App]
As you can see in the output, it contains runtime Microsoft.NETCore.App 8.0.0-rc.1.23419.4
.
Now we can use the image to deploy into Azure Container App environment. Refer to this code snippet Deploy Azure Function App with .NET 8 to Azure Container Apps via Bicep for more details.