SignalR: InvalidDataException: Reading 'target' as String failed.'

66 Views Asked by At

Trying to implement a chat function in my Blazor Server app with Azure identity platform. Locally I get the following error:

Connection disconnected with error 'Error: Server returned an error on close: Connection closed with an error. InvalidDataException: Reading 'target' as String failed.'.

I don't even know where the problem could be. I can't find anything online about this error. Been searching for days. Please can someone tell me what this could mean?

Also the connection is constantly attempting to reconnect (locally).

When I deploy to Azure App Service, the website immediately displays the generic "Error. An error occurred while processing your request."

Referring to the answer I got here: Authenticate HubConnection in Blazor Server with Microsoft Identity platform

For code reference: I have the exact same code in my project and it's not working. Does the error have something to do with Azure? Do I have to configure the app registration or the app service?

Please help me, trying to wrap my head around this for days.

1

There are 1 best solutions below

0
Jason Pan On BEST ANSWER

Adjusting the Microsoft.AspNetCore.SignalR.Client version to 7.0.15 can fix this issue.

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net7.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UserSecretsId>aspnet-BlazorApp1-10cc89a2-1c53-4291-9670-355f5f946eaf</UserSecretsId>
    <WebProject_DirectoryAccessLevelKey>0</WebProject_DirectoryAccessLevelKey>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="7.0.13" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="7.0.13" NoWarn="NU1605" />
    <PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="7.0.15" />
    <PackageReference Include="Microsoft.Identity.Web" Version="2.13.4" />
    <PackageReference Include="Microsoft.Identity.Web.UI" Version="2.13.4" />
  </ItemGroup>

</Project>

When I use 8.0.1 can reproduce the issue.