Skip to content

Blazor Server exception when using SignalR with AAD authentication  #37762

@ElBertrando

Description

@ElBertrando

I am using the tutorial here:
https://docs.microsoft.com/en-us/aspnet/core/tutorials/signalr-blazor?view=aspnetcore-5.0&tabs=visual-studio&pivots=server
in visual studio 2019. I then add Azure authentication to the code and add the correct Instance, Domain, TenantId, ClientId, CallbackPath in appsettings.json.

When i run the code I get exception error in the browser:

JsonReaderException: '<' is an invalid start of a value. LineNumber: 2 | BytePositionInLine: 0.

InvalidDataException: Invalid negotiation response received

Describe the bug

Adding AAD to the code with signalR connection produces exception.

To Reproduce

Relevant part of code:

    protected override async Task OnInitializedAsync()
    {
        _hubConnection = new HubConnectionBuilder()
            .WithUrl(NavigationManager.ToAbsoluteUri("/chathub"))
            .Build();

        _hubConnection.On<string, string>("ReceiveMessage", (user, message) =>
        {
            var encodedMsg = $"{user}: {message}";
            _messages.Add(encodedMsg);
            StateHasChanged();
        });

        await _hubConnection.StartAsync();
    }

Exceptions (if any)

JsonReaderException: '<' is an invalid start of a value. LineNumber: 2 | BytePositionInLine: 0.

System.Text.Json.ThrowHelper.ThrowJsonReaderException(ref Utf8JsonReader json, ExceptionResource resource, byte nextByte, ReadOnlySpan<byte> bytes)

InvalidDataException: Invalid negotiation response received.

Microsoft.AspNetCore.Http.Connections.NegotiateProtocol.ParseResponse(ReadOnlySpan<byte> content)

Further technical details

  • ASP.NET Core version: 5.0
  • The IDE (VS / VS Code/ VS4Mac) you're running on, and its version: Visual Studio 2019 version 16.11.5
  • Include the output of dotnet --info:
  • .NET SDK (reflecting any global.json):
    Version: 5.0.402
    Commit: e9d3381880

Runtime Environment:
OS Name: Windows
OS Version: 10.0.19043
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\5.0.402\

Host (useful for support):
Version: 5.0.11
Commit: f431858f8b

.NET SDKs installed:
5.0.102 [C:\Program Files\dotnet\sdk]
5.0.402 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions