英文:
.NET7 Azure Functions: the host has not yet started
问题
我想在我的笔记本电脑上使用Azure Functions来调试一个项目。项目使用C#编写,其中有一些函数需要连接到服务总线。该项目已经部署在Azure上并且正常运行。
在我的新笔记本电脑上,我已安装了Visual Studio 2022 Community (64位) - 预览版本 17.5.0 预览 6.0。
然后,我从Git仓库中拉取了项目,但当我运行项目时,我遇到了以下错误:
在启动操作期间发生了主机错误 '02312afe-22ad-4fdf-bb10-f4852471c73e'。
Microsoft.Azure.WebJobs.Script: 未找到语言为 [dotnet-isolated] 的函数。
Visual Studio显示以下代码行:
public Task StopAsync()
{
ThrowIfDisposed();
Interlocked.CompareExchange(ref _state, StateStoppingOrStopped, StateStarted);
if (_state != StateStoppingOrStopped)
{
throw new InvalidOperationException("The host has not yet started.");
}
}
这些代码来自JobHost.cs
(由Microsoft编写)。
根据这个帖子,我尝试安装Azure Functions Core Tools,但仍然遇到相同的错误。
该项目具有以下属性:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<ApplicationInsightsResourceId>/subscriptions/</ApplicationInsightsResourceId>
<UserSecretsId>d9d1dbff-5ee9-4590-ab74-4fbd7c563096</UserSecretsId>
</PropertyGroup>
<!-- 省略其他属性 -->
</Project>
我尝试在local.settings.json
中将FUNCTIONS_WORKER_RUNTIME
的值从dotnet-isolated
更改为powershell
,但仍然遇到相同的问题:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "powershell",
"SBConnectionString": "Endpoint=myconection"
}
}
因此,我尝试使用Visual Studio创建一个新的Azure Functions项目,使用.NET 7。在向导中,我添加了服务总线连接字符串和队列。但是我遇到了相似的错误。
如果我使用PowerShell运行Azurite
,我会遇到错误。当我在Visual Studio中打开项目时,我可以看到如下内容。
英文:
I want to debug on my laptop a project with Azure Functions. The language is C#. Few functions are using a connection to a service bus. This project is deployed already on Azure and it is working.
In my new laptop, I have installed Visual Studio 2022 Community (64 bit) - Preview Version 17.5.0 Preview 6.0.
Then, pull the project from the Git repository and when I run the project I get this error
> A host error has occurred during startup operation '02312afe-22ad-4fdf-bb10-f4852471c73e'.
>
> Microsoft.Azure.WebJobs.Script: Did not find functions with language [dotnet-isolated].
Visual Studio shows me those lines:
public Task StopAsync()
{
ThrowIfDisposed();
Interlocked.CompareExchange(ref _state, StateStoppingOrStopped, StateStarted);
if (_state != StateStoppingOrStopped)
{
throw new InvalidOperationException("The host has not yet started.");
}
that they are coming from JobHost.cs
(wrote by Microsoft)
Following this post, I tried to install the Azure Functions Core Tools but I get the same error.
The project has the following properties
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<ApplicationInsightsResourceId>/subscriptions/</ApplicationInsightsResourceId>
<UserSecretsId>d9d1dbff-5ee9-4590-ab74-4fbd7c563096</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.ApplicationInsights.WorkerService" Version="2.21.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.10.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.13" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.8.1" />
<PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.1.3" />
<PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ApplicationInsights" Version="1.0.0-preview4" />
<PackageReference Include="PSC.Extensions" Version="6.0.28" />
<PackageReference Include="WB.Domain" Version="1.2.44" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\WB.Api.Client\WB.Api.Client\WB.Api.Client.csproj" />
<ProjectReference Include="..\..\WB.Connections.Reverso\WB.Connections.Reverso\WB.Connections.Reverso.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
</Project>
I tried to change in the local.settings.json
the value FUNCTIONS_WORKER_RUNTIME
from dotnet-isolated
to powershell
but with the same issue.
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "UseDevelopmentStorage=true",
"FUNCTIONS_WORKER_RUNTIME": "powershell",
"SBConnectionString": "Endpoint=myconection"
}
}
So, then, I tried to create a new Azure Functions with Visual Studio with NET7. In the wizard I added the Service Bus connection string and the queue. The error is simular
Azurite
If I use the PowerShell to run Azurite
I get an error
When I open the project in Visual Studio I can see
答案1
得分: 1
在问题描述中,您提供了.NET 6 Azure Functions的.csproj
代码:
>
如果您要迁移到.NET 6/7隔离版本,则必须在local.settings.json
文件中将FUNCTIONS_WORKER_RUNTIME
设置为dotnet-isolated
,并按照用户@DwainBrowne在SO #69104798中给出的步骤进行操作。
以下是Azure Functions .NET 7隔离版本的.csproj
代码,其中包含Http和Service Bus触发器:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0-preview2" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
>Microsoft.Azure.WebJobs.Script: 未找到语言为[dotnet-isolated]的函数。
如果Functions项目不在PowerShell语言/运行时中,请不要使用powershell
值设置FUNCTIONS_WORKER_RUNTIME
。
>
我注意到您在使用Service Bus连接字符串时遇到了错误,例如'Endpoint=sb://wbreverso.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]'
缺失或为空。
当Service Bus连接字符串名称从local.settings.json
到函数代码不同时,将出现此错误。
您在local.settings.json
文件中定义了Service Bus连接字符串变量SBConnectionString
,在Service Bus触发器函数声明中应使用相同的名称。
public static void Run([ServiceBusTrigger("myqueue", Connection = "SBConnectionString")]
这是在本地IDE(Visual Studio、VS Code)中运行Service Bus触发器Azure Functions的情况。
当您在Azure Cloud中运行相同的Function项目时,您必须在应用程序设置配置部分中定义该Service Bus连接字符串。
有关Azure Functions Service Bus触发器连接绑定的更多信息,请参阅此MS Doc。
英文:
In the Question Description, you have given the .NET 6 Azure Functions .csproj
Code:
>
If you're migrating to .NET 6/7 Isolated Version, you have to set the FUNCTIONS_WORKER_RUNTIME
as dotnet-isolated
in the local.settings.json
file and follow the steps given in SO #69104798 by the user @DwainBrowne.
Below is the .csproj
code for Azure Functions .NET 7 Isolated Version with Http and Service Bus Trigger:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<AzureFunctionsVersion>v4</AzureFunctionsVersion>
<OutputType>Exe</OutputType>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Functions.Worker" Version="1.6.0" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.Http" Version="3.0.12" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Extensions.ServiceBus" Version="4.2.1" />
<PackageReference Include="Microsoft.Azure.Functions.Worker.Sdk" Version="1.7.0-preview2" />
</ItemGroup>
<ItemGroup>
<None Update="host.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Update="local.settings.json">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<CopyToPublishDirectory>Never</CopyToPublishDirectory>
</None>
</ItemGroup>
<ItemGroup>
<Using Include="System.Threading.ExecutionContext" Alias="ExecutionContext" />
</ItemGroup>
</Project>
>Microsoft.Azure.WebJobs.Script: Did not find functions with language [dotnet-isolated].
Do not use the powershell
value to the FUNCTIONS_WORKER_RUNTIME
if the Functions Project is not in the PowerShell Language/Runtime.
>
I have observed that you are getting the error in using the Service Bus Connection String such as 'Endpoint=sb://wbreverso.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]' is missing or empty.
This Error will come when the Service Bus Connection String Name is not the same from the local.settings.json
to the Function Code.
You have defined the Service Bus Connection String in the variable SBConnectionString
from the local.settings.json
file and same name should be used in the Service Bus Trigger Function Declaration.
public static void Run([ServiceBusTrigger("myqueue", Connection = "SBConnectionString")]
This is for running the Service Bus Trigger Azure Functions in the local IDEs (Visual Studio, VS Code).
When you are running the same Function project in Azure Cloud, you have to define that service bus connection string in the Application Settings Configuration Section.
Refer to this MS Doc for more information on Azure Functions Service Bus Trigger Connection Bindings.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论