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.

SignalR 6.x doesn't work with android il2cpp

See original GitHub issue

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

(Building with Unity) SignalR 6.x (6.0.0, 6.0.1, 6.0.2) doesn’t work with android on IL2CPP. Works fine on windows il2cpp builds. Reverting to 5.x fixes the issue.

Expected Behavior

No response

Steps To Reproduce

  • Create a unity project
  • Add SignalR 6.x libraries
  • Add a script that creates the hub connection, like this: var connection = new HubConnectionBuilder().WithUrl("http://localhost:5014/game").Build();
  • Build with Il2CPP to android
  • Exception (see below) is thrown when calling .Build()

Exceptions (if any)

03-06 12:42:04.721: E/Unity(28182): Parameter name: obj
03-06 12:42:04.721: E/Unity(28182):   at System.Threading.Monitor.ReliableEnterTimeout (System.Object obj, System.Int32 timeout, System.Boolean& lockTaken) [0x00000] in <00000000000000000000000000000000>:0 
03-06 12:42:04.721: E/Unity(28182):   at Microsoft.Extensions.DependencyInjection.DependencyInjectionEventSource.ServiceProviderBuilt (Microsoft.Extensions.DependencyInjection.ServiceProvider provider) [0x00000] in <00000000000000000000000000000000>:0 
03-06 12:42:04.721: E/Unity(28182):   at Microsoft.Extensions.DependencyInjection.ServiceProvider..ctor (System.Collections.Generic.ICollection`1[T] serviceDescriptors, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options) [0x00000] in <00000000000000000000000000000000>:0 
03-06 12:42:04.721: E/Unity(28182):   at Microsoft.Extensions.DependencyInjection.ServiceCollectionContainerBuilderExtensions.BuildServiceProvider (Microsoft.Extensions.DependencyInjection.IServiceCollection services, Microsoft.Extensions.DependencyInjection.ServiceProviderOptions options) [0x00000] in <00000000000000000000000000000000>:0 
03-06 12:42:04.721: E/Unity(28182):   at Mi```

### .NET Version

_No response_

### Anything else?

_No response_

Issue Analytics

  • State:open
  • Created 2 years ago
  • Reactions:2
  • Comments:5 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
kolesnickcommented, Sep 16, 2022

I use this workaround to bypass that error:

var connection =
    new HubConnection(
        new HttpConnectionFactory(
            new OptionsWrapper<HttpConnectionOptions>(new HttpConnectionOptions
            {
                Transports = WebSockets,
                SkipNegotiation = true,
            }),
            new NullLoggerFactory()),
        new NewtonsoftJsonHubProtocol(),
        new UriEndPoint(new Uri(url)),
        new DummyServiceProvider(),
        new NullLoggerFactory(),
        new DefaultRetryPolicy())
    {
        ServerTimeout = Timeout,
    };

await connection.StartAsync();

Also 2 additional classes are needed:

internal sealed class DummyServiceProvider : IServiceProvider
{
    public object GetService(Type serviceType) => throw new NotSupportedException();
}

internal sealed class DefaultRetryPolicy : IRetryPolicy
{
    private static readonly TimeSpan?[] RetryDelays = { Zero, FromSeconds(2), FromSeconds(10), FromSeconds(30), null, };

    public TimeSpan? NextRetryDelay(RetryContext retryContext) => RetryDelays[retryContext.PreviousRetryCount];
}
2reactions
cristoferfntcommented, Jun 13, 2022

Just tested the preview version (7.x), and the exception still occours. Will be using 5.0.17 for our project, but would like to use the newer version. When I have time, I’ll try to debug this more.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SignalR HubConnectionBuilder fails when run ... - Issue Tracker
Go to Window > Package Manager and add Android LogCat from Unity Registry 5. Go to Window > Analysis and open the Android...
Read more >
[Unity] Communicate with SignalR from Unity
I can connect SignalR hub by AspNetCore.SignalR.Client. ... One important problem is I can't use NuGet for Unity applications.
Read more >
Adding Unity Support - SignalR in Unity - Part 2 - YouTube
That Unity and our SignalR server can connect with one another. ... channel in the Microsoft Reactor ( and even come to our...
Read more >
Unity: SignalR connection working in editor but not ...
I am a beginner, I have connected SignalR to my application, it works fine, it sends / receives data. But everything works only...
Read more >
NET 4.6 Dll's references problem
So the idea is to put SignalR 2.2.2 inside Unity. Everything works just fine : I managed to change the target framework to...
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