0

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

enter image description here

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)

enter image description here

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

enter image description here

Azurite

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

enter image description here

When I open the project in Visual Studio I can see

enter image description here

Enrico
  • 3,592
  • 6
  • 45
  • 102

1 Answers1

1

In the Question Description, you have given the .NET 6 Azure Functions .csproj Code:

enter image description here

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.


enter image description here

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.