Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

.NET Standard

Discussion in 'Scripting' started by Qbit86, Jan 16, 2017.

  1. echebkeso

    echebkeso

    Joined:
    Jul 2, 2018
    Posts:
    3
    Do you happen to have a list of the deps? I published a mostly empty project from Visual Studio referencing Microsoft.AspNetCore.SignalR.Client 1.0.1 (.netstandard 2.0) and thought that would be them all:

    Microsoft.AspNetCore.Connections.Abstractions.dll
    Microsoft.AspNetCore.Http.Connections.Client.dll
    Microsoft.AspNetCore.Http.Connections.Common.dll
    Microsoft.AspNetCore.Http.Features.dll
    Microsoft.AspNetCore.SignalR.Client.Core.dll
    Microsoft.AspNetCore.SignalR.Client.dll
    Microsoft.AspNetCore.SignalR.Common.dll
    Microsoft.AspNetCore.SignalR.Protocols.Json.dll
    Microsoft.Extensions.Configuration.Abstractions.dll
    Microsoft.Extensions.Configuration.Binder.dll
    Microsoft.Extensions.Configuration.dll
    Microsoft.Extensions.DependencyInjection.Abstractions.dll
    Microsoft.Extensions.DependencyInjection.dll
    Microsoft.Extensions.Logging.Abstractions.dll
    Microsoft.Extensions.Logging.dll
    Microsoft.Extensions.Options.dll
    Microsoft.Extensions.Primitives.dll
    Newtonsoft.Json.dll
    SignalRTest.dll
    System.IO.Pipelines.dll
    System.Runtime.CompilerServices.Unsafe.dll
    System.Threading.Channels.dll

    but I still get the rather unhelpful "Unloading broken assembly Assets/Plugins/Microsoft.AspNetCore.SignalR.Client.Core.dll, this assembly can cause crashes in the runtime" (Unity 2018.1.6f1) - only a handful of these load in Unity

    Thanks :)
     
    dzmitry-lahoda likes this.
  2. echebkeso

    echebkeso

    Joined:
    Jul 2, 2018
    Posts:
    3
    Right, I figured out the dependencies in the end and SignalR Core works like a charm in the Unity Editor on Mac, yay!

    However.. deployed to an iOS device I get the following when building the hub, any ideas?

    InvalidOperationException: A suitable constructor for type 'Microsoft.AspNetCore.SignalR.Client.HttpConnectionFactory' 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 (System.Type serviceType, System.Type implementationType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (Microsoft.Extensions.DependencyInjection.ServiceDescriptor descriptor, System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.TryCreateExact (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteFactory.CreateCallSite (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.CallSiteChain callSiteChain) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.CreateServiceAccessor (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0
    at System.Func`2[T,TResult].Invoke (T arg) [0x00000] in <00000000000000000000000000000000>:0
    at System.Collections.Concurrent.ConcurrentDictionary`2[TKey,TValue].GetOrAdd (TKey key, System.Func`2[T,TResult] valueFactory) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType, Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngineScope serviceProviderEngineScope) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceLookup.ServiceProviderEngine.GetService (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceProvider.GetService (System.Type serviceType) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.Extensions.DependencyInjection.ServiceProviderServiceExtensions.GetService[T] (System.IServiceProvider provider) [0x00000] in <00000000000000000000000000000000>:0
    at Microsoft.AspNetCore.SignalR.Client.HubConnectionBuilder.Build () [0x00000] in <00000000000000000000000000000000>:0
    at NetworkController.<StartTest>m__0 (System.String user, System.String message) [0x00000] in <00000000000000000000000000000000>:0
    at System.Net.Http.Headers.HttpHeaders.SetValue[T] (System.String name, T value, System.Func`2[T,TResult] toStringConverter) [0x00000] in <00000000000000000000000000000000>:0
    at NetworkController.StartTest () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Events.UnityAction.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Events.InvokableCall.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.Events.UnityEvent.Invoke () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UI.Button.Press () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UI.Button.OnPointerClick (UnityEngine.EventSystems.PointerEventData eventData) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.ExecuteEvents.Execute (UnityEngine.EventSystems.IPointerClickHandler handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1].Invoke (T1 handler, UnityEngine.EventSystems.BaseEventData eventData) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.ExecuteEvents.Execute[T] (UnityEngine.GameObject target, UnityEngine.EventSystems.BaseEventData eventData, UnityEngine.EventSystems.ExecuteEvents+EventFunction`1[T1] functor) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchPress (UnityEngine.EventSystems.PointerEventData pointerEvent, System.Boolean pressed, System.Boolean released) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.StandaloneInputModule.ProcessTouchEvents () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.StandaloneInputModule.Process () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.EventSystems.EventSystem.Update () [0x00000] in <00000000000000000000000000000000>:0
    --- End of stack trace from previous location where exception was thrown ---
    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw () [0x00000] in <00000000000000000000000000000000>:0
    at System.Runtime.CompilerServices.AsyncMethodBuilderCore+<>c.<ThrowAsync>b__6_0 (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    at System.Threading.SendOrPostCallback.Invoke (System.Object state) [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UnitySynchronizationContext.Exec () [0x00000] in <00000000000000000000000000000000>:0
    at UnityEngine.UnitySynchronizationContext.ExecuteTasks () [0x00000] in <00000000000000000000000000000000>:0

    (Filename: currently not available on il2cpp Line: -1)
     
    dzmitry-lahoda likes this.
  3. echebkeso

    echebkeso

    Joined:
    Jul 2, 2018
    Posts:
    3
    Just an update for anyone reading, had another poke around at this. Turns out IL2CPP on my iOS build is stripping away "unused" parts of assemblies to save size (by using static analysis, which isn't clever enough to pick up on the DI used here I guess), this can be avoided by using a "link.xml" to ensure none of the ASPNetCore SignalR libraries are "stripped" and I've sorted the above issue now and can trigger Methods from iOS Client -> Server it looks like.

    Next problem, the version of Newtonsoft JSON that SignalR Core uses - involves dynamic code generation which is prohibited on IOS so back to square 0 I think (as I'm now getting an error about 'system.reflection.emit' or similar not being implemented) - so currently can't handle method calls locally on IOS.
     
    arufolo and dzmitry-lahoda like this.
  4. Dustin-Horne

    Dustin-Horne

    Joined:
    Apr 4, 2013
    Posts:
    4,568
    Use my version of Newtonsoft off the asset store.. it's free and fixes that issue by not using IL.Emit.
     
    dzmitry-lahoda likes this.
  5. snarlynarwhal

    snarlynarwhal

    Joined:
    Jan 16, 2014
    Posts:
    29
    @echebkeso I'm having the exact same issue. What did you end up doing to fix the dependencies?
     
  6. dzmitry-lahoda

    dzmitry-lahoda

    Joined:
    Oct 9, 2018
    Posts:
    4
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
  8. VarrialeCiro

    VarrialeCiro

    Joined:
    Oct 26, 2018
    Posts:
    1
    I still find this error:

    Unloading broken assembly Assets/Plugins/Microsoft.AspNetCore.SignalR.Client.dll, this assembly can cause crashes in the runtime
    using Unity 2018.2.13f with this player settings:

    Scripting Runtime Versione: .NET 4.x Equivalent
    Scripting Backend: IL2CPP
    Api Compatibility Level*: .NET Standard 2.0

    The command used to download AspNetCore.SignalR.Client nuget is the following:

    > Nuget Install Microsoft.AspNetCore.SignalR.Client -OutputDirectory SignalR

    (tried with different version, preview too)

    The Unload broken assembly errors happen also for some dependencies. Don't know how to solve. Maybe I have to wait Unity fixes the problem.

    Someone solved?
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
    Please try this with Unity 2018.3 beta. We have improved the error message to provide a few more details. Maybe it will help.
     
  10. Qbit86

    Qbit86

    Joined:
    Sep 2, 2013
    Posts:
    487
    When will 2018.3 be released out of beta?
     
  11. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,773
    I'm not entirely sure yet, but it looks like early December.
     
    dzmitry-lahoda and Qbit86 like this.
  12. geretti

    geretti

    Joined:
    Dec 20, 2016
    Posts:
    10
    We're looking to do the same thing at our company, bringing SignalR client libraries onto Unity.

    I just tried it with 2018.3.0b3 (thanks Josh) and the error messages are more verbose, complaining about missing libraries. I added all the missing libraries and then brought them onto my main 2018.2.x project and it works. Only tested on MacOS Editor targeting iOS so far. Still have to go through IL2CPP.

    I'm attaching the full set of libraries (I haven't pruned them, so some some may not be necessary) I needed to add in addition to Newtonsoft.Json:

    MicrosoftLibraries.png SytemLibraries.png

    I built the .dll on .NET 4.7.1 with Rider 2018.2.3
     
    Last edited: Nov 5, 2018
  13. tg_sentio

    tg_sentio

    Joined:
    Sep 20, 2018
    Posts:
    1
    I am trying to do the same thing with SignalR using Windows Editor 2018.3.0b8 - but I can't see more detailed errors messages. I have a couple of assemblies that fail to load and a handful more that complains about crashes in the runtime.

    Where should I be able to find the verbose messages?

    @geretti: How are you creating your HubConnection?
     
  14. geretti

    geretti

    Joined:
    Dec 20, 2016
    Posts:
    10
  15. DrMaxP

    DrMaxP

    Joined:
    Sep 18, 2018
    Posts:
    27
    I'm seeing issues on our test servers targeting 2108.1.9 only on Mac with .NET Standard 2.0 API compatibility, in that the project looks like it's compiling against a different API compatibility level. Was this issue ever resolved or explained?
     
  16. fredczj

    fredczj

    Joined:
    Apr 4, 2017
    Posts:
    7
    Hi,
    I am also working on the SignalRCore client application which fails on ios.
    Thanks to @geretti 's screenshots, I have filled-up the Assets/Plugins directory. Everything works on Mac with Unity in-simulator, but I collect an error about DI on iOs. It seems I missed so module, but I cannot see how to solve it:

    A suitable constructor for type 'Microsoft.Extensions.Options.OptionsManager`1[Microsoft.AspNetCore.Http.Connections.Client.HttpConnectionOptions]' could not be located. Ensure the type is concrete and services are registered for all parameters of a public constructor.

    I fails while building a HubConnection object:

    Code (CSharp):
    1.            
    2. Task.Run( () => {
    3.                this.__conn = new HubConnectionBuilder()
    4.                 .WithUrl("https://myapi.com/hub/", options =>
    5.                 {
    6.                     options.AccessTokenProvider = () => Task.FromResult(__token);
    7.                 })
    8.                 .Build();
    9. [...] });
    10.  
    My link.xml:
        <assembly fullname="Microsoft">
    <type fullname="Microsoft.*" preserve="all" />
    </assembly>


    <assembly fullname="System">
    <type fullname="System.*" preserve="all" />
    </assembly>


    Can anyone tell me what I should be missing?
     
    Last edited: Jul 10, 2019
  17. fredczj

    fredczj

    Joined:
    Apr 4, 2017
    Posts:
    7
    @echebkeso, could you please share your link.xml file. It seems my problem is equivalent to the one you solved already...
     
  18. SamuelGoldenbaum

    SamuelGoldenbaum

    Joined:
    May 21, 2017
    Posts:
    47
    Anyone ever get MessagePack integrated?
     
  19. SamuelGoldenbaum

    SamuelGoldenbaum

    Joined:
    May 21, 2017
    Posts:
    47
  20. SamuelGoldenbaum

    SamuelGoldenbaum

    Joined:
    May 21, 2017
    Posts:
    47
  21. jbassking

    jbassking

    Joined:
    Feb 27, 2014
    Posts:
    106
    @fredczj Did you ever get it working?