Reputation: 890
I'm trying to migrate an Azure Function that works perfectly on .NET 3.1 to .NET 5. I followed Microsoft's GitHub guide and still can't get it to run or debug locally (didn't even try to publish to Azure).
I'm getting this error:
[2021-09-05T09:49:33.066Z] A host error has occurred during startup operation 'bb37a6db-b6f4-4396-bb9b-cb5ae0bba387'.
[2021-09-05T09:49:33.067Z] Microsoft.Azure.WebJobs.Script: Failed to start Language Worker Channel for language :dotnet-isolated.
This is my Program.cs:
static async Task Main(string[] args)
{
var host = new HostBuilder()
.ConfigureAppConfiguration(c =>
{
c.AddCommandLine(args);
})
.ConfigureServices(s =>
{
s.AddLogging();
})
.Build();
await host.RunAsync();
}
This is my project file:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net5.0</TargetFramework>
<AzureFunctionsVersion>v3</AzureFunctionsVersion>
<UserSecretsId>76d0a5ed-221b-4b35-8ff4-3ee33d393196</UserSecretsId>
<OutputType>Exe</OutputType>
<_FunctionsSkipCleanOutput>true</_FunctionsSkipCleanOutput>
</PropertyGroup>
<ItemGroup>
<None Remove="global.json" />
</ItemGroup>
<ItemGroup>
<Content Include="global.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.5.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Storage" Version="4.0.4" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.0.4" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="5.0.2" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.11.1" />
<PackageReference Include="System.Linq.Async" Version="5.0.0" />
</ItemGroup>
<ItemGroup>
<None Update="config.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
My local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "HIDDEN",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
}
}
My host.json:
{
"logging": {
"fileLoggingMode": "always",
"logLevel": {
//"QueueWorkers.EmailQueueWorker": "Trace",
//"QueueWorkers.EmailQueueWorker.EmailQueueWorker": "Trace",
"default": "Information",
"Function": "Trace",
"Host.Results": "Error",
"Host.Aggregator": "Trace"
},
"applicationInsights": {
//"samplingExcludedTypes": "Request",
"samplingSettings": {
"isEnabled": true
}
},
"console": {
"isEnabled": "true"
}
},
"Values": {
"AzureWebJobsStorage": "HIDDEN",
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
},
"extensions": {
"queues": {
"maxDequeueCount": 5,
"maxPollingInterval": "00:00:02"
}
},
"version": "2.0"
}
Thanks
Upvotes: 21
Views: 32789
Reputation: 6345
I had a brand new Azure Function App with .NET 8. I could start it via Visual Studio but not with the CLI. The CLI command func start
produced this exact error:
Microsoft.Azure.WebJobs.Script: Failed to start Language Worker Channel for language :dotnet-isolated.
It turned out I was missing a package reference in my .csproj file. I had to add the last package reference in the <ItemGroup>
.
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.20.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.1.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.16.2" />
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.ApplicationInsights" Version="1.0.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
</ItemGroup>
Upvotes: 0
Reputation: 962
For those who went through all the steps in the other answers and their functions still wouldn't load (no functions found error), check in the project file if there is this line (it was the issue for me)
<None Remove="Microsoft.Azure.Functions.Extensions" />
after removing this line, the functions started to load.
Upvotes: 0
Reputation: 4603
In order to debug startup errors, I used Microsoft's suggestion of catching any startup errors and logging them to Application Insights. Specifically,
try
{
// do all your DI stuff
}
catch (Exception ex)
{
var config = new TelemetryConfiguration
{
ConnectionString = Environment.GetEnvironmentVariable("APPLICATIONINSIGHTS_CONNECTION_STRING")
};
var client = new TelemetryClient(config);
client.TrackException(ex);
client.Flush();
throw;
}
Upvotes: 0
Reputation: 4994
The same error can also occur when switching from MSDeploy to ZipDeploy (as MS suggests one should do) and the function app is not configured yet.
Check your target app service also has package enabled:
WEBSITE_RUN_FROM_PACKAGE
: 1
Read more: Run your functions from a package file in Azure.
Upvotes: 0
Reputation: 801
In Azure navigate to your Function and then in the section Settings -> Configuration change the Application settings:
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
Upvotes: 43
Reputation: 39
If everything is ok with your code (FunctionName attribute is now Function, and some other details), you may still have to remove unnecessary references like:
Microsoft.Azure.Functions.Extensions
Microsoft.Azure.WebJobs.Extensions
Microsoft.Azure.WebJobs.Extensions.ServiceBus
Microsoft.Azure.WebJobs.Extensions.Storage
Microsoft.Azure.WebJobs.Extensions.Tables
Microsoft.NET.Sdk.Functions
Also, don't forget to change the output type, as already said here
<OutputType>Exe</OutputType>
Of course, you should have included a new Program.cs
file (there is a good example in a comment above).
Upvotes: 0
Reputation: 1656
Since it is not working locally, you need to comment/remove the setting:
"FUNCTIONS_WORKER_RUNTIME": "dotnet"
OR
"FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
from your local.settings.json file.
In Azure, you need to make sure you have this setting in.
Upvotes: 3
Reputation: 1090
Had a similar problem in Visual Studio 2022, while trying to migrate a project from .net 5 to .net 6 functions...
kept telling me "Microsoft.Azure.WebJobs.Script: Did not find functions with language [dotnet-isolated]"
1) I was missing: Program.cs
using Microsoft.Azure.Functions.Worker.Configuration;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using System.Threading.Tasks;
namespace Main.Function
{
public class Program
{
public static void Main()
{
var host = new HostBuilder()
.ConfigureFunctionsWorkerDefaults()
.Build();
host.Run();
}
}
}
2) Edit .csproj > Under ItemGroup...
Remove:
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.0.1" />
Replace with
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.3.0" OutputItemType="Analyzer" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.WebJobs.Script.ExtensionsMetadataGenerator" Version="4.0.1" />
3) Ensure OutputType is set to exe
<OutputType>Exe</OutputType>
4) Unload project and reload (delete bin and obj folder before building)
Upvotes: 40
Reputation: 890
Well, still couldn't directly launch and debug from VS 2019 but function does work if launched from CLI and debug is working.
Debugger.Launch();
to Program.cs (first line of Main method)<LangVersion>preview</LangVersion>
in your csproj (right after TargetFramework). This missing line was actually the critical difference that stopped my function from working.Thanks
Upvotes: 0