Search code examples
azure-functionsrider

Unable to run Azure Functions project locally in Rider after adding plugins


I added some plugins so I could work with Azure Functions + Azure Service Bus, and since have been unable to run functions locally through Rider.

I tried:

  • deleting bin and obj folders
  • uninstalling Azure Toolkit for Rider
  • deleting ~\.AzureToolsForIntelliJ and ~\.azurefunctions
  • invalidating cache and restarting Rider
  • reinstalling Azure Toolkit for Rider
  • upgrading all Nuget packages to latest

But these didn't work.

I encounter this error when pressing the button to Run the local Azure function configuration:

System.Private.CoreLib: Exception has been thrown by the target of an invocation. Microsoft.Azure.WebJobs.Extensions.Storage.Queues: Could not load file or assembly 'System.Memory.Data, Version=6.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.
Value cannot be null. (Parameter 'provider')

And I encounter this error when trying to run it directly from func.exe:

C:\Users\mail\.AzureToolsForIntelliJ\AzureFunctionsCoreTools\v4\4.104.0\func.exe host start --verbose --pause-on-error --port 7070
MSBuild version 17.8.3+195e7f5a3 for .NET
...
...
...
FUNCTIONS_INPROC_NET8_ENABLED app setting is not enabled in local.settings.json
Selected inproc6 host.
This version of the Azure Functions Core Tools requires your project to reference version 4.5.0 or later of Microsoft.NET.Sdk.Functions. Please update to the latest version. For more information, see: https://aka.ms/functions-core-tools-in-proc-sdk-requirement

This is odd because it's suggesting that my Microsoft.NET.Sdk.Functions is out of date. However, looking at .csproj, it is not:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <AzureFunctionsVersion>v4</AzureFunctionsVersion>
        <RootNamespace />
    </PropertyGroup>
    <PropertyGroup Condition="'$(Configuration)' == 'Release'">
        <RuntimeIdentifier>win-x86</RuntimeIdentifier>
        <PublishReadyToRun>true</PublishReadyToRun>
    </PropertyGroup>
    <ItemGroup>
        <PackageReference Include="Azure.Messaging.ServiceBus" Version="7.18.2" />
        <PackageReference Include="Azure.Storage.Queues" Version="12.21.0" />
        <PackageReference Include="Microsoft.Azure.Cosmos" Version="3.46.0-preview.2" />
        <PackageReference Include="Microsoft.Azure.Functions.Extensions" Version="1.1.0" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" />
        <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.Storage.Queues" Version="5.3.3" />
        <PackageReference Include="Microsoft.Extensions.Configuration.AzureAppConfiguration" Version="8.1.0-preview" />
        <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
        <PackageReference Include="PlayFabAllSDK" Version="1.192.241108" />
        <PackageReference Include="Sentry.AspNetCore" Version="4.13.0" />
        <PackageReference Include="Sentry.Extensions.Logging" Version="4.13.0" />
        <PackageReference Include="SharpZipLib" Version="1.4.2" />
        <PackageReference Include="System.Memory" Version="4.6.0" />
    </ItemGroup>
    <ItemGroup>
        <None Update="host.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>
        <None Update="local.settings.json">
            <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            <CopyToPublishDirectory>Never</CopyToPublishDirectory>
        </None>
    </ItemGroup>
</Project>

This is the func.exe version:

C:\Users\mail\.AzureToolsForIntelliJ\AzureFunctionsCoreTools\v4\4.104.0\func.exe --version                              
4.0.6610

Any pointers would be appreciated 🙏


Solution

    • Support of .NET 6 has stopped from 12th November 2024, so you need to use .NET 8 but I can see in your .csproj file that you are still using .NET 6.

    • If you would like to run Service Bus triggered In-Process function then you should need below packages in your .csproj file.

    <Project Sdk="Microsoft.NET.Sdk">
        <PropertyGroup>
            <TargetFramework>net8.0</TargetFramework>
            <AzureFunctionsVersion>v4</AzureFunctionsVersion>
            <RootNamespace>_79189045</RootNamespace>
        </PropertyGroup>
        <ItemGroup>
            <PackageReference Include="Microsoft.Azure.WebJobs.Extensions.ServiceBus" Version="5.16.4" />
            <PackageReference Include="Microsoft.NET.Sdk.Functions" Version="4.6.0" />
        </ItemGroup>
        <ItemGroup>
            <None Update="host.json">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
            </None>
            <None Update="local.settings.json">
                <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
                <CopyToPublishDirectory>Never</CopyToPublishDirectory>
            </None>
        </ItemGroup>
    </Project>
    

    Also, FUNCTIONS_INPROC_NET8_ENABLED set to 1 in local settings file.

    {
        "IsEncrypted": false,
        "Values": {
            "AzureWebJobsStorage": "UseDevelopmentStorage=true",
            "FUNCTIONS_INPROC_NET8_ENABLED": "1",
            "FUNCTIONS_WORKER_RUNTIME": "dotnet",
            "ServiceBusConnectionString": "Endpoint=sb://afreensb.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=95Gb*****tTJM4="
        }
    }
    

    By doing the given changes, you can run the service bus triggered function locally in Rider.

    Azure Functions Core Tools
    Core Tools Version:       4.0.6518 Commit hash: N/A +74ed9095fdd6c5326276aae6b8a7d41ccbdeb6aa (64-bit)
    Function Runtime Version: 4.35.4.23179
    
    [2024-11-15T10:51:45.180Z] Found C:\Users\*****\RiderProjects\79189045\79189045\79189045.csproj. Using for user secrets file configuration.
    
    Functions:
    
            ServiceBusTriggeredFunction: serviceBusTrigger
    
    For detailed output, run func with --verbose flag.
    [2024-11-15T10:52:58.126Z] Executing 'ServiceBusTriggeredFunction' (Reason='(null)', Id=b4f30256-77aa-4469-be01-72b4e7a12283)
    [2024-11-15T10:52:58.130Z] Trigger Details: MessageId: 3c75615a8f3c4bc3939c7da0db414d40, SequenceNumber: 1, DeliveryCount: 1, EnqueuedTimeUtc: 2024-11-15T10:52:57.2600000+00:00, LockedUntilUtc: 2024-11-15T10:53:57.2760000+00:00, SessionId: (null)
    [2024-11-15T10:52:58.147Z] C# ServiceBus queue trigger function processed message: Hi, This is a test message
    [2024-11-15T10:52:58.173Z] Executed 'ServiceBusTriggeredFunction' (Succeeded, Id=b4f30256-77aa-4469-be01-72b4e7a12283, Duration=100ms)