.NET 7 Azure Functions:主机尚未启动

huangapple go评论61阅读模式
英文:

.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].

.NET 7 Azure Functions:主机尚未启动

Visual Studio shows me those lines:

public Task StopAsync()
{
    ThrowIfDisposed();

    Interlocked.CompareExchange(ref _state, StateStoppingOrStopped, StateStarted);

    if (_state != StateStoppingOrStopped)
    {
        throw new InvalidOperationException(&quot;The host has not yet started.&quot;);
    }

that they are coming from JobHost.cs (wrote by Microsoft)

.NET 7 Azure Functions:主机尚未启动

Following this post, I tried to install the Azure Functions Core Tools but I get the same error.

The project has the following properties

&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;net6.0&lt;/TargetFramework&gt;
    &lt;AzureFunctionsVersion&gt;v4&lt;/AzureFunctionsVersion&gt;
    &lt;ApplicationInsightsResourceId&gt;/subscriptions/&lt;/ApplicationInsightsResourceId&gt;
    &lt;UserSecretsId&gt;d9d1dbff-5ee9-4590-ab74-4fbd7c563096&lt;/UserSecretsId&gt;
  &lt;/PropertyGroup&gt;
  &lt;ItemGroup&gt;
    &lt;PackageReference Include=&quot;Microsoft.ApplicationInsights.WorkerService&quot; Version=&quot;2.21.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.10.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Http&quot; Version=&quot;3.0.13&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.WebJobs.Extensions.ServiceBus&quot; Version=&quot;5.8.1&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.NET.Sdk.Functions&quot; Version=&quot;4.1.3&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.WebJobs.Extensions.ApplicationInsights&quot; Version=&quot;1.0.0-preview4&quot; /&gt;
    &lt;PackageReference Include=&quot;PSC.Extensions&quot; Version=&quot;6.0.28&quot; /&gt;
    &lt;PackageReference Include=&quot;WB.Domain&quot; Version=&quot;1.2.44&quot; /&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;ProjectReference Include=&quot;..\..\WB.Api.Client\WB.Api.Client\WB.Api.Client.csproj&quot; /&gt;
    &lt;ProjectReference Include=&quot;..\..\WB.Connections.Reverso\WB.Connections.Reverso\WB.Connections.Reverso.csproj&quot; /&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;None Update=&quot;host.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
    &lt;/None&gt;
    &lt;None Update=&quot;local.settings.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
      &lt;CopyToPublishDirectory&gt;Never&lt;/CopyToPublishDirectory&gt;
    &lt;/None&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;

I tried to change in the local.settings.json the value FUNCTIONS_WORKER_RUNTIME from dotnet-isolated to powershell but with the same issue.

{
    &quot;IsEncrypted&quot;: false,
    &quot;Values&quot;: {
        &quot;AzureWebJobsStorage&quot;: &quot;UseDevelopmentStorage=true&quot;,
        &quot;FUNCTIONS_WORKER_RUNTIME&quot;: &quot;powershell&quot;,
        &quot;SBConnectionString&quot;: &quot;Endpoint=myconection&quot;
    }
}

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

.NET 7 Azure Functions:主机尚未启动

Azurite

If I use the PowerShell to run Azurite I get an error

.NET 7 Azure Functions:主机尚未启动

When I open the project in Visual Studio I can see

.NET 7 Azure Functions:主机尚未启动

答案1

得分: 1

在问题描述中,您提供了.NET 6 Azure Functions的.csproj代码:

>.NET 7 Azure Functions:主机尚未启动

如果您要迁移到.NET 6/7隔离版本,则必须在local.settings.json文件中将FUNCTIONS_WORKER_RUNTIME设置为dotnet-isolated,并按照用户@DwainBrowne在SO #69104798中给出的步骤进行操作。

以下是Azure Functions .NET 7隔离版本的.csproj代码,其中包含Http和Service Bus触发器:

&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;net7.0&lt;/TargetFramework&gt;
    &lt;AzureFunctionsVersion&gt;v4&lt;/AzureFunctionsVersion&gt;
    &lt;OutputType&gt;Exe&lt;/OutputType&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
  &lt;/PropertyGroup&gt;
  &lt;ItemGroup&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.6.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Http&quot; Version=&quot;3.0.12&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.ServiceBus&quot; Version=&quot;4.2.1&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.7.0-preview2&quot; /&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;None Update=&quot;host.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
    &lt;/None&gt;
    &lt;None Update=&quot;local.settings.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
      &lt;CopyToPublishDirectory&gt;Never&lt;/CopyToPublishDirectory&gt;
    &lt;/None&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;Using Include=&quot;System.Threading.ExecutionContext&quot; Alias=&quot;ExecutionContext&quot; /&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;

>Microsoft.Azure.WebJobs.Script: 未找到语言为[dotnet-isolated]的函数。

如果Functions项目不在PowerShell语言/运行时中,请不要使用powershell值设置FUNCTIONS_WORKER_RUNTIME


>.NET 7 Azure Functions:主机尚未启动

我注意到您在使用Service Bus连接字符串时遇到了错误,例如&#39;Endpoint=sb://wbreverso.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]&#39;缺失或为空。

当Service Bus连接字符串名称从local.settings.json到函数代码不同时,将出现此错误。

您在local.settings.json文件中定义了Service Bus连接字符串变量SBConnectionString,在Service Bus触发器函数声明中应使用相同的名称。

public static void Run([ServiceBusTrigger(&quot;myqueue&quot;, Connection = &quot;SBConnectionString&quot;)]

这是在本地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:

>.NET 7 Azure Functions:主机尚未启动

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:

&lt;Project Sdk=&quot;Microsoft.NET.Sdk&quot;&gt;
  &lt;PropertyGroup&gt;
    &lt;TargetFramework&gt;net7.0&lt;/TargetFramework&gt;
    &lt;AzureFunctionsVersion&gt;v4&lt;/AzureFunctionsVersion&gt;
    &lt;OutputType&gt;Exe&lt;/OutputType&gt;
    &lt;ImplicitUsings&gt;enable&lt;/ImplicitUsings&gt;
    &lt;Nullable&gt;enable&lt;/Nullable&gt;
  &lt;/PropertyGroup&gt;
  &lt;ItemGroup&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker&quot; Version=&quot;1.6.0&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.Http&quot; Version=&quot;3.0.12&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Extensions.ServiceBus&quot; Version=&quot;4.2.1&quot; /&gt;
    &lt;PackageReference Include=&quot;Microsoft.Azure.Functions.Worker.Sdk&quot; Version=&quot;1.7.0-preview2&quot; /&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;None Update=&quot;host.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
    &lt;/None&gt;
    &lt;None Update=&quot;local.settings.json&quot;&gt;
      &lt;CopyToOutputDirectory&gt;PreserveNewest&lt;/CopyToOutputDirectory&gt;
      &lt;CopyToPublishDirectory&gt;Never&lt;/CopyToPublishDirectory&gt;
    &lt;/None&gt;
  &lt;/ItemGroup&gt;
  &lt;ItemGroup&gt;
    &lt;Using Include=&quot;System.Threading.ExecutionContext&quot; Alias=&quot;ExecutionContext&quot; /&gt;
  &lt;/ItemGroup&gt;
&lt;/Project&gt;

>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.


>.NET 7 Azure Functions:主机尚未启动

I have observed that you are getting the error in using the Service Bus Connection String such as &#39;Endpoint=sb://wbreverso.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;[Hidden Credential]&#39; 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(&quot;myqueue&quot;, Connection = &quot;SBConnectionString&quot;)]

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.

huangapple
  • 本文由 发表于 2023年2月8日 23:07:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75387727.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定