Trying to use Microsoft.AspNetCore.SignalR.Client (6.0.0) in a Azure Function 4.0 (.Net Core Project).

Dey, Subir 0 Reputation points
2023-09-05T18:20:37.67+00:00

Trying to use Microsoft.AspNetCore.SignalR.Client (6.0.0) in a Azure Function 4.0 (.Net Core Project). I am getting this error in the azure Function code while invoking the code

            var hubConnection = new HubConnectionBuilder()
                        .WithUrl("https://hub-web.azurewebsites.net/hub")
                        .Build();
            await hubConnection.StartAsync();

            await hubConnection.InvokeAsync("SendNotification");

System.Private.CoreLib: Exception while executing function: Test. Microsoft.AspNetCore.SignalR.Client.Core: The type initializer for 'Microsoft.AspNetCore.SignalR.Client.HubConnection' threw an exception. Microsoft.AspNetCore.SignalR.Client.Core: Could not load file or assembly 'System.Threading.Channels, Version=7.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'. The system cannot find the file specified.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
Developer technologies ASP.NET ASP.NET Core
{count} votes

1 answer

Sort by: Most helpful
  1. navba-MSFT 27,540 Reputation points Microsoft Employee Moderator
    2023-09-06T04:36:18.1833333+00:00

    @Dey, Subir Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    I see that you are trying to use Microsoft.AspNetCore.SignalR.Client (6.0.0) in an Azure Function 4.0 (.Net Core Project) and encountering an error while invoking the code. Specifically, the error message states that the type initializer for 'Microsoft.AspNetCore.SignalR.Client.HubConnection' threw an exception, and the system cannot find the file specified.

    Based on the error message you provided, it seems that the type initializer for 'Microsoft.AspNetCore.SignalR.Client.HubConnection' threw an exception, and the system cannot find the file specified. This error message can occur due to several reasons, including:

    • Missing or incorrect reference to the System.Threading.Channels assembly.
    • Incompatible versions of the SignalR client and server libraries.
    • Incorrect URL or configuration settings.

    To resolve this issue, you can try the following solutions:

    1. Firstly, the Microsoft.AspNetCore.SignalR.Client 6.0 version seems to be an older version. Could you please upgrade it to the most recent stable version 7.0.10 ? See here.
    2. Also Ensure that the System.Threading.Channels assembly is referenced correctly in your project. You can check the NuGet package manager to see if the package is installed and up-to-date. If not, you can install it by running the following command in the Package Manager Console:
    Install-Package System.Threading.Channels -Version 7.0.0
    
    1. Please open your Functions csproj file and check if you have any incorrect dependencies added for System.Threading.Channels within the PackageReference.
    2. Please ensure that it works fine locally (on your VS dev box) at your end before deploying it to the Azure Function.
    3. Please follow this article and leverage the sample code provided here
    4. Check if the SignalR client and server libraries are compatible. You can refer to the following documentation to ensure that you are using the correct versions:

    If you still encounter the same issue, Please do reach out to me. I would be happy to help.

    **
    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.