I am having a similar issue as #10080. I am using preview 6 of asp.net core SignalR client inside of unity and compiling with IL2CPP. I created a small git repo with the code I use to reproduce this issue
I am running into an exception when starting the connection:
connection = new HubConnectionBuilder()
.WithUrl("http://localhost:5000/gamehub")
.Build(); // works fine
await connection.StartAsync(); // takes a few sec before failing
The connection.StartAsync
fails with the following exception:
InvalidDataException: Missing required property 'connectionId'.
at Microsoft.AspNetCore.Http.Connections.NegotiateProtocol.ParseResponse (System.ReadOnlySpan`1[T] content)
Unity's IL2CPP strips unused assemblies. It caused another issue but I fixed that by adding link.xml file. So the issue described here should not be affected by code stripping.
I don't currently have unity on any of my work machines, but I might try this out on a personal machine to see if I can figure anything out.
Meanwhile, is it possible for you to grab the network trace so we can verify what payload the client is receiving from the server?
@BrennanConroy I am not sure how to take a network trace. I set both of my server and client to verbose debug logging. The logs are included in the git repo above (server and client)
If I can provide better traces please let me know how :)
Also of note, when I build with the mono runtime the handshake succeeds. I would guess this is a client side error instead of server side.
Thanks for the help!
@thorgeirk11 We have some guidance on network traces here: https://docs.microsoft.com/en-us/aspnet/core/signalr/diagnostics?view=aspnetcore-2.2
InvalidDataException: Missing required property 'connectionId'.
This indicates that the response from the server is incorrect (missing a required property). Can you provide a sample response from the localhost:5000/gamehub/negotiate
endpoint (you can just use a browser to do this).
Unity apparently doesn't play well with fiddler so after testing out different tools I managed to get a network trace through WireShark. See NetworkTraces.zip
As far as I can see both the IL2CPP and Mono receive the same response.
Request:
POST /gamehub/negotiate HTTP/1.1
User-Agent: Microsoft.AspNetCore.Http.Connections.Client/3.0.0-preview6.19307.2
X-Requested-With: XMLHttpRequest
Content-Length: 0
Connection: keep-alive
Host: signalr-il2cpp-test.azurewebsites.net
Response:
HTTP/1.1 200 OK
Content-Length: 252
Content-Type: application/json
Server: Microsoft-IIS/10.0
X-Powered-By: ASP.NET
Set-Cookie: ARRAffinity=cfe9d88b4d05c4f99a90649b783196ca671405478765ab764374675d71877225;Path=/;HttpOnly;Domain=signalr-il2cpp-test.azurewebsites.net
Date: Wed, 17 Jul 2019 18:40:52 GMT
{"connectionId":"5wLJLrzOr3q7VfCRrGx-7w","availableTransports":[{"transport":"WebSockets","transferFormats":["Text","Binary"]},{"transport":"ServerSentEvents","transferFormats":["Text"]},{"transport":"LongPolling","transferFormats":["Text","Binary"]}]}
Can you investigate if the deserialization mechanism is AOT (IL2CPP) compatible?
Unity has wide adoption of IL2CPP and on some platform that is the only scripting runtime available, such as iOS and WebGL.
Please let me know if I can provide more info, check out the git repo for my simple project that reproduces this error.
I haven't gotten the chance to try out the repo project yet (thanks for that btw!).
I did take a glance at the project though, and how does it know what version of the client to download and use?
Also, could you try to replace the json protocol to use Newtonsoft and see if it works with that?
Here are the steps to switch to newtonsoft, note you need to add another package (for the link.xml file).
@thorgeirk11 any update/success connecting from IL2CPP Unity client?
Sort of having the same issue ages ago and decided to use a plugin from the AssetStore by then.
But really looking fwd to using asp.net core SignalR client straight into Unity instead.
We would also really like to use the official signalR client in unity
@crevelop Nope not yet, I guess the problem would be solved by switching out the serializer for an AOT friendly implementation. I have not spent much time on it. The game I am working on is on standalone and currently using Mono. However, in the coming months, I would like the option to switch to IL2CPP to export to WebGL.
You may need to use Linker.xml to avoid field stripping
Check out my repo. I induded a Linker.xml for all of the SignalR binaries.
Hello @thorgeirk11 ! Is the SignalR core running with Unity finally ? I would like to integrate it on Hololens but at this time I've not found any documentation to do this. You are my last hope :)
@samoteph It works out of the box for any platform that does not require IL2CPP.
However, it appears that MessagePack supports IL2CPP platforms. I will have to test it out for myself, but it looks promising.
We also encounter this problem : (
Hope that it will get fixed.
@samoteph It works out of the box for any platform that does not require IL2CPP.
However, it appears that MessagePack supports IL2CPP platforms. I will have to test it out for myself, but it looks promising.
Did you have any luck with messagepack?
Finally, I rewrote my own sharing service with WebSocket as a communication channel
Anyone get messagepack working? I added an entry to my link.xml file to the Microsoft.AspNetCore.SignalR.Protocols.MessagePack.dll, but I get missing constructor error.
Yeah, we are currently using Messagepack successfully
Yeah, we are currently using Messagepack successfully
@thorgeirk11 great to hear - to confirm: are you using it with IL2CPP (iOS)?
After downloading v3.1.2, I have extracted the netstandard2.0 Microsoft.AspNetCore.SignalR.Protocols.MessagePack.dll
I then added an additional entry in my link.xml
file as follows:
<assembly fullname="Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol" preserve="all"/>
Yet when I run it on a device, I get the following error:
InvalidOperationException: A suitable constructor for type 'Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.
at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateConstructorCallSite (Microsoft.Extensions.DependencyInjection.ServiceLookup.ResultCache lifetime, System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0
Could you list the steps you guys are taking to get it working in your project?
My link.xml file:
<linker>
<assembly fullname="System.Core">
<type fullname="System.Linq.Expressions.Interpreter.LightLambda" preserve="all" />
</assembly>
<assembly fullname="MessagePack" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Connections.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Features" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Common" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Protocol.MessagePackHubProtocol" preserve="all"/>
<assembly fullname="Microsoft.Extensions.DependencyInjection.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Options" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Primitives" preserve="all"/>
<assembly fullname="System.Buffers" preserve="all"/>
<assembly fullname="System.IO.Pipelines" preserve="all"/>
<assembly fullname="System.Memory" preserve="all"/>
<assembly fullname="System.Numerics.Vectors" preserve="all"/>
<assembly fullname="System.Runtime.CompilerServices.Unsafe" preserve="all"/>
<assembly fullname="System.Threading.Tasks.Extensions" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Connections.Client" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.Http.Connections.Common" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Client.Core" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Client" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Protocols.Json" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Configuration.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Configuration.Binder" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Configuration" preserve="all"/>
<assembly fullname="Microsoft.Extensions.DependencyInjection" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Logging.Abstractions" preserve="all"/>
<assembly fullname="Microsoft.Extensions.Logging" preserve="all"/>
<assembly fullname="System.ComponentModel.Annotations" preserve="all"/>
<assembly fullname="System.Text.Json" preserve="all"/>
<assembly fullname="System.Threading.Channels" preserve="all"/>
<assembly fullname="Microsoft.AspNetCore.SignalR.Protocols.NewtonsoftJson" preserve="all"/>
</linker>
Ah I have yet to Port my project over to IL2CPP however I assume to get that working you would have to pre-compile a message pack parser.
Ah I have yet to Port my project over to IL2CPP however I assume to get that working you would have to pre-compile a message pack parser.
Works fine under mono - but iOS now only allows IL2CPP which is the stumbling block.
Could you advise on process to pre-compile a message pack parser.
Take a look at https://github.com/neuecc/MessagePack-CSharp#aot
Take a look at https://github.com/neuecc/MessagePack-CSharp#aot
Thanks, been trying to get this running but no luck. Let me know if you get it working with IL2CPP.
Has anyone gotten this to work?
Has anyone gotten this to work?
Yes, but not with messagepack on IL2CPP.
@samuelgoldenbaum what鈥檚 your environment?
I am currently in the process of porting my project over to use a precompiled message pack formatter and IL2CPP
I encountered this issue but have yet to see if the solution pointed out works.
Just for reference, I just created an issue on the MessagePack Repo.
MessagePack.dll is not supported in IL2CPP and the two solutions don't work well together.
@davidfowl 猬嗭笍 Don't know who should take lead on fixing this because of the interplay between SignalR and Messagepack :shrug:
Hey.
Are there any updates regarding this issue?
I would like to use unity as a frontend for a UWP AR application. However using AspNetCore.SignalR somehow only works in the Unity editor, but not the UWP build.
Funny thing, while I use a similiar approach as @thorgeirk11 in his original statement, I do not receive any exception at all.
Thanks for contacting us.
We're moving this issue to the Next sprint planning
milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Whenever there's an update on this, we'd be happy to help test. Have a decent size environment with 10K concurrent users 1M daily that has worked well with SignalR for realtime info on the web. Would like to use same backend within Unity on iOS/Android.
Thanks for contacting us.
We're moving this issue to the Next sprint planning
milestone for future evaluation / consideration. We will evaluate the request when we are planning the work for the next milestone. To learn more about what to expect next and how this issue will be handled you can read more about our triage process here.
Any news on this? My comp would like to use SignalR Core with Unity, too.
Edit: I saw that https://github.com/neuecc/MessagePack-CSharp/issues/973 was fixed. So does this work now?
We haven't done any testing on Unity. If you would like to help us out by testing with those changes, that would be great.
Brain dump:
IL2CPP:
System.Linq.Expressions
https://forum.unity.com/threads/are-c-expression-trees-or-ilgenerator-allowed-on-ios.489498/#post-3667969MessagePack:
ref MessagePackWriter
which isn't supported in IL2CPPSystem.Text.Json:
General:
cc @jkotas for awareness (AOT stuff)
You make it sound like there's a problem with MessagePack, but it's hard to run a library that doesn't consider to Unity.
My MagicOnion has a complete AOT generator for Unity and providing a SignalR-like API.
@neuecc It wasn't meant to sound as if MessagePack is a problem, @BrennanConroy was just exploring the space and posting his findings. If we misrepresented MessagePack-CSharp in anyway please correct it so we can learn (this is a learning experience for us).
To your other point this is correct, we haven't historically been AOT friendly but that's one of the things we plan to work on going forward (as a strategy), which is why it's important to understand the current warts (which we have some basic idea of)
@davidfowl regarding my past experiences with using SignalR in Unity I'd second the statement of @neuecc. It is really hard to use any .NET library, that wasn't meant to be used in Unity. Apart from not always playing super nice with IL2CPP the .NET SignalR client pulls in a quite sizable amount of ASP.NET Core dependencies. That works fine for anything that uses NuGet but it falls flat in Unity (afaik the Unity package manger has no NuGet interop). If it is the goal to write a Unity client for SignalR I'd basically treat it as I would any non CLR language (like Java, JS, etc) and don't try to force the conventional client into an environment where it is setup for failure.
Most helpful comment
We would also really like to use the official signalR client in unity