aspnetcore: SignalR 6.x doesn't work with android il2cpp
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_
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 3
- Comments: 17 (1 by maintainers)
I use this workaround to bypass that error:
Also 2 additional classes are needed:
@Deusald, thank you for sending me your example, it helped me. So I’ve figured out what is different. Wanna suggest to all non-experienced in Unity (like me), that came here to this discussion, please take a look if you have link.xml file in your Unity project. I put this file in the same folder where I have all my dlls. Long story short - this file makes that your dlls during il2cpp (Intermediate Language To C++) convertion will be not clipped. Here is official documentation regarding that: https://docs.unity3d.com/Manual/ManagedCodeStripping.html My file for example looks like this:
Also be carefull and use two spaces on the beginning of the line instead of tab, because with tabs it doesn’t work, at least on my side.
@Marik0511 I pulled SignalR code from my project. SignalRTest.zip There is an example server and client in unity. I tested it by making Andoird IL2CPP build and everything worked correctly. I was able to connect to server on my pc, send and receive messages.
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.
This is my hub connection creation code on unity client:
I’m using unity 2023.2.20f1 and signalR in version 8.0.3 building for Android with IL2CPP and everything is working fine for me.
@Marik0511 It’s been a while since I had this issue, but I think I solved it by using Newtonsoft.JSON instead of MessagePack, as maybe MessagePack was doing some reflection which IL2CPP doesn’t support.
EDIT: The workaround used to work on SignalR Core 6.0.922.41926