DEV Community

[Unity] Communicate with SignalR from Unity

Masui Masanori on March 30, 2021

Intro This time, I will try communicating with SignalR from Unity applications. For server side, I will use the application what I creat...
Collapse
 
warriorwork profile image
WarriorWork • Edited

Thanks for great tutorial!
I get the error in picture..
dev-to-uploads.s3.amazonaws.com/up...
I have to use the newtonsoft.Json 8.0.0.0 because I use it for IBM plugin...

What can I do?

Thanks!

Collapse
 
masanori_msl profile image
Masui Masanori • Edited

Thank you for reading my post.

I have to use the newtonsoft.Json 8.0.0.0 because I use it for IBM plugin...
What can I do?

I think it's hard to resolve :(.
Because "Microsoft.AspNetCore.SignalR.Client" requires .NET Standard 2.0 compatibility from ver.1.0.0.

nuget.org/packages/Microsoft.AspNe...

But Newtonsoft.Json has supported .NET Standard 2.0 from ver.11.

github.com/JamesNK/Newtonsoft.Json...

So I think it's better to find out how to force to use Newtonsoft.Json version 11 or later.

Collapse
 
warriorwork profile image
WarriorWork

Hey I think I resolved the problem!
At the begining I was following this tutorial:
youtube.com/watch?v=ntqxSSWG66g
And he uses Newtonsoft... then I pay attenion to your post and you didnt use it.
So I was following your tutorial post and it works good I dont need to change my newtonsoft to any versions

Thank you!

Collapse
 
warriorwork profile image
WarriorWork

Hi!
In Mac OS it should work? Because when I run it on MAC I cannot connect to the Server by:
connection = new HubConnectionBuilder()
.WithUrl("localhost:5000/chatHub")
.Build();

The HubConnection.ConnectionID is empty. In others platforms it works but only in MacOS it doesn't work... Do you have any idea?

Collapse
 
rathsocheat profile image
Rath Socheat • Edited

I have problem when build for android.

  • Editor: Works
  • IOS: Works
  • Android: Errors

Environments

  • Unity ver.2022.3.11f1
  • Framework .netstandard ver 2.1
  • Microsoft.AspNetCore.SignalR.Client ver 7.0.0 [I already tried same version as yours it doesn't work too]

Image description

Error 1:

C:\Program Files\Unity\Hub\Editor\2021.3.11f1\Editor\Data\il2cpp\build\deploy\il2cpp.exe --convert-to-cpp --data-folder=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Library/Bee/artifacts/Android/il2cppOutput/data --generatedcppdir=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Library/Bee/artifacts/Android/il2cppOutput/cpp --enable-analytics --emit-null-checks --enable-array-bounds-check --dotnetprofile=unityaot-linux --profiler-report --profiler-output-file=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Library/Bee/artifacts/il2cpp_conv_oudx.traceevents --print-command-line
Error: IL2CPP error (no further information about what managed code was being converted is available)
System.InvalidOperationException: Sequence contains no elements
at System.Linq.ThrowHelper.ThrowNoElementsException()
at System.Linq.Enumerable.First[TSource](IEnumerable
1 source)
at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.Initialize(UnderConstruction2& systemAssembly)
at Unity.IL2CPP.DataModel.BuildLogic.DataModelBuilder.Build()
at Unity.IL2CPP.Contexts.Components.DataModelComponent.Load(LoadSettings loadSettings, Boolean ownsTypeContext, Boolean ownsBuilder, DataModelBuilder& builder)
at Unity.IL2CPP.AssemblyConversion.Phases.InitializePhase.Run(AssemblyConversionContext context)
at Unity.IL2CPP.AssemblyConversion.Classic.ClassicConverter.Run(AssemblyConversionContext context)
at Unity.IL2CPP.AssemblyConversion.AssemblyConverter.ConvertAssemblies(AssemblyConversionInputData data, AssemblyConversionParameters parameters, AssemblyConversionInputDataForTopLevelAccess dataForTopLevel)
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Error 2:
Building D:\Nimets\Projects\KhmerChess\KhmerChessClient\Library\Bee\artifacts\unitylinker_xy1a.traceevents failed with output:
C:\Program Files\Unity\Hub\Editor\2021.3.11f1\Editor\Data\il2cpp\build\deploy\UnityLinker.exe --search-directory=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed --out=Library/Bee/artifacts/Android/ManagedStripped --include-link-xml=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed\MethodsToPreserve.xml --include-link-xml=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed\TypesInScenes.xml --include-link-xml=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed\SerializedTypes.xml --include-link-xml=D:\Nimets\Projects\KhmerChess\KhmerChessClient\Temp\burst.link.xml --include-link-xml=D:\Nimets\Projects\KhmerChess\KhmerChessClient\Assets\link.xml --include-link-xml=D:\Nimets\Projects\KhmerChess\KhmerChessClient\Assets\Packages\FacebookSDK\link.xml --include-link-xml=C:/Program Files/Unity/Hub/Editor/2021.3.11f1/Editor/Data/PlaybackEngines/AndroidPlayer/Tools/AndroidNativeLink.xml --include-directory=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed --profiler-report --profiler-output-file=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Library/Bee/artifacts/unitylinker_xy1a.traceevents --dotnetprofile=unityaot-linux --dotnetruntime=Il2Cpp --platform=Android --use-editor-options --enable-engine-module-stripping --engine-modules-asset-file=C:/Program Files/Unity/Hub/Editor/2021.3.11f1/Editor/Data/PlaybackEngines/AndroidPlayer/modules.asset --editor-data-file=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/EditorToUnityLinkerData.json --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Universal.Runtime.dll --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/Unity.TextMeshPro.dll --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/Unity.RenderPipelines.Core.Runtime.dll --include-unity-root-assembly=D:/Nimets/Projects/KhmerChess/KhmerChessClient/Temp/StagingArea/Data/Managed/Facebook.Unity.Settings.dll --print-command-line --enable-analytics
Fatal error in Unity CIL Linker
System.NullReferenceException: Object reference not set to an instance of an object.
at Unity.Linker.Analytics.AnalyticsService.RecognizedReflectionAccessPattern(IMemberDefinition source, Instruction sourceInstruction, IMetadataTokenProvider accessedItem)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.MarkTypeForDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, TypeDefinition typeDefinition, DynamicallyAccessedMemberTypes requiredMemberTypes)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.RequireDynamicallyAccessedMembers(ReflectionPatternContext& reflectionContext, DynamicallyAccessedMemberTypes requiredMemberTypes, ValueNode value, IMetadataTokenProvider targetContext)
at Mono.Linker.Dataflow.ReflectionMethodBodyScanner.ProcessGenericArgumentDataFlow(GenericParameter genericParameter, TypeReference genericArgument, IMemberDefinition source)
at Mono.Linker.Steps.MarkStep.MarkGenericArgumentConstructors(IGenericInstance instance, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkGenericArguments(IGenericInstance instance, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.GetOriginalType(TypeReference type, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementation(InterfaceImplementation iface, TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkInterfaceImplementations(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkRequirementsForInstantiatedTypes(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference, DependencyInfo reason, IMemberDefinition sourceLocationMember)
at Mono.Linker.Steps.MarkStep.InitializeType(TypeDefinition type)
at Mono.Linker.Steps.MarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Unity.Linker.Steps.UnityMarkStep.InitializeAssembly(AssemblyDefinition assembly)
at Mono.Linker.Steps.MarkStep.Initialize()
at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
at Unity.Linker.Steps.UnityMarkStep.Process(LinkContext context)
at Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
at Mono.Linker.Pipeline.Process(LinkContext context)
at Unity.Linker.UnityDriver.UnityRun(Boolean noProfilerAllowed, ILogger customLogger)
at Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling(ILogger customLogger, Boolean noProfilerAllowed)
at Unity.Linker.UnityDriver.RunDriver()
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)

Error 3:
BuildFailedException: Incremental Player build failed!
UnityEditor.Modules.BeeBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args) (at <4e64905d831f4883a53259ef37fb023b>:0)
UnityEditor.Modules.DefaultBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <4e64905d831f4883a53259ef37fb023b>:0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at <5e58a3838afa4e88a08dc92f05003dcc>:0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.Int32 subtarget, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <4e64905d831f4883a53259ef37fb023b>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)

Collapse
 
rathsocheat profile image
Rath Socheat

Problem solve by update editor to ver.2022.3.16f1

Collapse
 
garethjones99 profile image
garethjones99

Hey Masui,

Thanks for the tutorial,

I can get it working for the editor, however when I build for android I'm getting errors in the app when calling .Build on the HubConnectionBuilder. It's possibly related to the DependancyInjection lib

I've posted in more detail here on the unity forums and was wondering if you could share any insight as to what may be causing this or if you have experienced this error before.

Thanks

Collapse
 
garethjones99 profile image
garethjones99

For anyone else with this issue it was fixed using this work around github.com/dotnet/aspnetcore/issue...

Collapse
 
pereviader profile image
Pere Viader

One important problem is I can't use NuGet for Unity applications. So I must put dlls into the Assets/Plugins folder manually.

You might be interested in this project I did github.com/PereViader/CSharpProjec...
It might help you integrate any c# project as a unity package

Collapse
 
jason_becker_xp profile image
Jason Becker

Great Walkthru!!!!

Collapse
 
439_th_713063ff2bdf6d33bc profile image
439 th

This is cool, but I want to put in something that simply shows updating data from another website. Which one of these scripts does that? Do I need to use two of them?