question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Blazor wasm signalr client logging doesn't exist

See original GitHub issue

Describe the bug

There is currently no documented, working, simple, way to add signalr logging to a .NET client running in blazor-wasm.

The tutorial Use ASP.NET Core SignalR with Blazor WebAssembly implies that this is a supported workflow, and the Logging and diagnostics page provides the instructions for the .NET client used in the tutorial. However, on attempting to follow these instructions, a System.NotSupportedException: Cannot start threads on this runtime stack trace is produced and the application crashes.

Workarounds: I’ve attempted to work around this by using Blazor.Extensions.Logging but this doesn’t seem to work as the provider is internal. I’ve tried to create a custom provider, but gave up after an hour.

Am I missing something really obvious? Shouldn’t simple logging be working out of the box?

To Reproduce

I’ve created a repro in https://github.com/tboby/blazor-wasm-signalr-logging

master: The tutorial code, with up to date packages and css (so it actually builds).

signalr-logging-tutorial: A single commit with the modification as recommended in the documentation, and in issue #22687 .

  1. Clone the repo
  2. Checkout master
  3. Run the Server project and see that the tutorial project works
  4. Checkout signal-logging-tutorial
  5. Run the Server project and see the browser console for the stack trace

Exceptions (if any)

Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Cannot start threads on this runtime.
System.NotSupportedException: Cannot start threads on this runtime.
  at (wrapper managed-to-native) System.Reflection.RuntimeConstructorInfo.InternalInvoke(System.Reflection.RuntimeConstructorInfo,object,object[],System.Exception&)
  at System.Reflection.RuntimeConstructorInfo.InternalInvoke (System.Object obj, System.Object[] parameters, System.Boolean wrapExceptions) <0x264d878 + 0x0001e> in <filename unknown>:0 
--- End of stack trace from previous location where exception was thrown ---

  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00108> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitIEnumerable (Microsoft.Extensions.DependencyInjection.ServiceLookup.IEnumerableCallSite enumerableCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bc3a0 + 0x00056> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x00082> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00072> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitConstructor (Microsoft.Extensions.DependencyInjection.ServiceLookup.ConstructorCallSite constructorCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28bbff0 + 0x00072> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSiteMain (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2855838 + 0x000a8> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngine, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverLock lockType) <0x28b9278 + 0x000ce> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.VisitRootCache (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite singletonCallSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.RuntimeResolverContext context) <0x28b8ea0 + 0x0002e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteVisitor`2[TArgument,TResult].VisitCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, TArgument argument) <0x2852f90 + 0x000a6> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteRuntimeResolver.Resolve (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceCallSite callSite, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) <0x28529e8 + 0x0002c> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.DynamicServiceProviderEngine+<>c__DisplayClass1_0.<RealizeService>b__0 (Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope scope) <0x2852800 + 0x00062> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) <0x2846c40 + 0x0006c> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) <0x2838228 + 0x0000e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) <0x28380d8 + 0x0000e> in <filename unknown>:0 
  at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) <0x2d60958 + 0x00022> in <filename unknown>:0 
  at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () <0x2d60858 + 0x00030> in <filename unknown>:0 
  at BlazorSignalRApp.Client.Pages.Index.OnInitializedAsync () [0x00012] in C:\Users\Thomas\Git\blazor-wasm-signalr-logging\Client\Pages\Index.razor:37 
  at Microsoft.AspNetCore.Components.ComponentBase.RunInitAndSetParametersAsync () <0x2c1fde0 + 0x0013a> in <filename unknown>:0

Further technical details

ASP.NET Core version: 3.2.0, see project file https://github.com/tboby/blazor-wasm-signalr-logging/blob/signalr-logging-tutorial/Client/BlazorSignalRApp.Client.csproj

.NET Core SDK (reflecting any global.json):
 Version:   3.1.300
 Commit:    b2475c1295

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

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  3.0.100 [C:\Program Files\dotnet\sdk]
  3.1.102 [C:\Program Files\dotnet\sdk]
  3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Using VS Enterprise 16.6.1, but can reproduce with dotnet run

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
tbobycommented, Jun 9, 2020

@mkArtakMSFT Sorry, again, but I don’t see how that helps in this situation. I think I’ve worked out how to do it, see below.

This is not documented at all, and the current documentation doesn’t work.

@mandalorianbob I think I might have found the solution though!

@inject ILoggerProvider loggingprovider;

        hubConnection = new HubConnectionBuilder()
            .WithUrl(NavigationManager.ToAbsoluteUri("/chatHub"))
            .ConfigureLogging(logging =>
                logging.AddProvider(loggingprovider))
            .Build();

image

I think this issue is still valid, as the documentation is incorrect, and worse, leads users down a rabbit hole of irrelevant configuration.

0reactions
captainsafiacommented, Jun 10, 2020

Perhaps. The issue seems to be a disconnect in the docs that the SignalR tutorial provides on logging and what we currently support.

The SignalR logging docs (ref) assumes that you are running in a .NET client on the server but when running in Blazor, we need to inject the WebAssemblyConsoleLoggerProvider so that the logs show up correctly in the browser console.

@guardrex Perhaps we can write a brief snippet on this in the logging docs?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR Troubleshooting
The solution is to stop the SignalR connection before logging the client out. "Uncaught Error: SignalR: jQuery not found. Please ensure jQuery ...
Read more >
Blazor WebAssembly Logging is not honoring ...
It means if you are not enabling "Verbose/Detailed" logging probably won't see Debug and Trace logs. Check your settings. In Chrome it is...
Read more >
Asp.Net Core SignalR on Blazor Server-Side never calls ...
I created a basic Blazor Server-Side chat, but OnDisconnectedAsync is never called, the connection stays alive even when the browser is closed.
Read more >
Using SignalR in your Blazor applications - YouTube
In this episode, David Pine joins Jeremy to show off this chat bot enabled demo that's powered by Blazor WASM and SignalR [00:00]...
Read more >
How to Build and Secure Web Applications with Blazor
Learn how to build client-side Web apps using Blazor and how to secure them with Auth0 authentication and authorization features.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found