Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SignalR callbacks working on net7.0, not on net9.0 #58485

Closed
1 task done
ispysoftware opened this issue Oct 17, 2024 · 9 comments
Closed
1 task done

SignalR callbacks working on net7.0, not on net9.0 #58485

ispysoftware opened this issue Oct 17, 2024 · 9 comments
Labels
area-signalr Includes: SignalR clients and servers Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue

Comments

@ispysoftware
Copy link

ispysoftware commented Oct 17, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Updating from net7.0 to net9.0 breaks all callbacks from signalr.

When running this code under net7.0 it works fine, i see "SignalR connection established." followed by messages coming in on "ProcessJSON". I change to net9.0 and I just see "SignalR connection established." - nothing is logged and no messages arrive.

Expected Behavior

Should function exactly the same as net7.0

Steps To Reproduce

See repro project

https://github.com/ispysoftware/sigrtest9/tree/main

The test fails. Change the net runtime from net9.0 to net7,0 in the project file and the test passes
Set Trimming to false and the test passes.

Exceptions (if any)

No response

.NET Version

net9.0

Anything else?

No response

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-signalr Includes: SignalR clients and servers label Oct 17, 2024
@BrennanConroy BrennanConroy added the Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue label Oct 17, 2024
@dotnet-policy-service dotnet-policy-service bot added the Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. label Oct 17, 2024
@ispysoftware
Copy link
Author

ispysoftware commented Oct 18, 2024

It's due to trimming - working in net7.0 with trimming enabled. Broken in net8.0 with trimming enabled
<PublishTrimmed>true</PublishTrimmed>

#41704

Is there any workaround using TrimmerRootAssembly?

@dotnet-policy-service dotnet-policy-service bot added Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. and removed Needs: Author Feedback The author of this issue needs to respond in order for us to continue investigating this issue. labels Oct 18, 2024
@BrennanConroy
Copy link
Member

Trimming isn't supported for SignalR in .NET 8.

@ispysoftware
Copy link
Author

ispysoftware commented Oct 18, 2024

@BrennanConroy - yes i've spent 3 days finding that out. Do you know if it's supported in .NET 9? The reason I ask is that with trimming our client facing app is 50mb and without it it's 140mb.

publishing a trimmed app with signalr on net8.0 doesn't give any trim warnings.

@BrennanConroy
Copy link
Member

#41704 (comment)

@ispysoftware
Copy link
Author

ispysoftware commented Oct 21, 2024

Thanks @BrennanConroy .
Spent the last 3 days updating our codebase to be compatible with net9.0 and having exactly the same issue with SignalR.
Just says
"SignalR connection established" and nothing else. No messages back from it.

I've linked a repro demonstrating the issue to
#41704 (comment)

@ispysoftware ispysoftware reopened this Oct 21, 2024
@BrennanConroy
Copy link
Member

You are still using the 8.0 package... Trimming support was added in the 9.0 version which means you need the 9.0 package.

@ispysoftware
Copy link
Author

Thanks @BrennanConroy - I updated the reference to the latest pre-release. Same issue.

@ispysoftware ispysoftware changed the title SignalR callbacks working on net7.0, not on net8.0 SignalR callbacks working on net7.0, not on net9.0 Oct 21, 2024
@BrennanConroy
Copy link
Member

var builder = new HubConnectionBuilder().WithUrl("...")
    .ConfigureLogging(l =>
    {
        l.AddConsole();
    });
builder.Services.Configure<JsonHubProtocolOptions>(o =>
{
    o.PayloadSerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});
var connection = builder.Build();

[JsonSerializable(typeof(string))]
internal partial class AppJsonSerializerContext : JsonSerializerContext { }

If you turned on logging you would see an error about Json serialization that would point you in the right direction.

The above code works if you only want to receive strings, but you can of course change it for your specific app.

https://learn.microsoft.com/aspnet/core/release-notes/aspnetcore-9.0?view=aspnetcore-8.0#signalr-supports-trimming-and-native-aot

@ispysoftware
Copy link
Author

@BrennanConroy Thanks, adding

builder.Services.Configure<JsonHubProtocolOptions>(o =>
{
    o.PayloadSerializerOptions.TypeInfoResolverChain.Insert(0, AppJsonSerializerContext.Default);
});

resolved it. Much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-signalr Includes: SignalR clients and servers Needs: Attention 👋 This issue needs the attention of a contributor, typically because the OP has provided an update. Needs: Repro Indicates that the team needs a repro project to continue the investigation on this issue
Projects
None yet
Development

No branches or pull requests

2 participants