dotnet / dotnet/aspnetcore

[NET 9] [Blazor/SignalR] `InvalidOperationException`: Trying to set an Activity that is not running

Open
#59,792 6 comments 1 reaction 0 assignees View on GitHub
area-signalr
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

Currently migrating my project to .NET 9 and noticed a bunch of `InvalidOperationException`s happening with my server-side blazor application:

> Trying to set an Activity that is not running

The seem to happen during SignalR message handling:

>System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.NotifyError(System.Exception exception) C#
System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.ValidateSetCurrent(System.Diagnostics.Activity activity) C#
System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.Current.set(System.Diagnostics.Activity value) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher.Invoke.__ExecuteInvocation|22_0(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher dispatcher, Microsoft.Extensions.Internal.ObjectMethodExecutor methodExecutor, Microsoft.AspNetCore.Components.Server.ComponentHub hub, object[] arguments, Microsoft.Extensions.DependencyInjection.AsyncServiceScope scope, Microsoft.AspNetCore.SignalR.IHubActivator hubActivator, Microsoft.AspNetCore.SignalR.HubConnectionContext connection, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage hubMethodInvocationMessage, bool isStreamCall) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher.Invoke(Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor descriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext connection, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage hubMethodInvocationMessage, bool isStreamResponse, bool isStreamCall) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.ChannelBasedSemaphore.RunTask<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>(System.Func<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage), System.Threading.Tasks.Task> callback, (Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage) state) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.ChannelBasedSemaphore.RunAsync<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage)>(System.Func<(Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage), System.Threading.Tasks.Task> callback, (Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher, Microsoft.AspNetCore.SignalR.Internal.HubMethodDescriptor, Microsoft.AspNetCore.SignalR.HubConnectionContext, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage) state) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher.ProcessInvocation(Microsoft.AspNetCore.SignalR.HubConnectionContext connection, Microsoft.AspNetCore.SignalR.Protocol.HubMethodInvocationMessage hubMethodInvocationMessage, bool isStreamResponse) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.Internal.DefaultHubDispatcher.DispatchMessageAsync(Microsoft.AspNetCore.SignalR.HubConnectionContext connection, Microsoft.AspNetCore.SignalR.Protocol.HubMessage hubMessage) C#
Microsoft.AspNetCore.SignalR.Core.dll!Microsoft.AspNetCore.SignalR.HubConnectionHandler.DispatchMessagesAsync(Microsoft.AspNetCore.SignalR.HubConnectionContext connection) C#

### Expected Behavior

_No response_

### Steps To Reproduce

It's a larger project so it will take some time to repro this. I just wonder this error is known already?

### Exceptions (if any)

_No response_

### .NET Version

9.0.101

### Anything else?

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.