Search Unity

Resolved Mlagents library grpc issue in one project but works in another project without any issues

Discussion in 'ML-Agents' started by Gistiv, Jun 24, 2021.

  1. Gistiv

    Gistiv

    Joined:
    Apr 22, 2014
    Posts:
    13
    I started using mlagents a few days ago and picked up a demo project and had some fun with it. Then after some time it was time to integrate it into my current project. After setting everything up exactly the same as in the demo project (Editor 2019.4.2f, Mlagents 1.6.0 with the associated python environment). But when trying to connect to the training backend I only got a message saying that it couldn't connect. I completly switched off the firewall but still no connection.

    I debugged into the code of mlagents and found out that there is a try-catch block which doesn't handle exceptions and only throws a not connected message.
    This is the exception that originally gets thrown but isn't handled or displayed:


    System.IO.IOException: Error loading native library "\Library\PackageCache\com.unity.ml-agents@1.6.0-preview\Plugins\ProtoBuffer\runtimes/win/native\grpc_csharp_ext.x64.dll"
    at Grpc.Core.Internal.UnmanagedLibrary..ctor (System.String[] libraryPathAlternatives) [0x00063] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Internal.NativeExtension.Load () [0x000d7] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Internal.NativeExtension..ctor () [0x00006] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Internal.NativeExtension.Get () [0x00022] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Internal.NativeMethods.Get () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.GrpcEnvironment.GrpcNativeInit () [0x00000] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.GrpcEnvironment..ctor () [0x0001e] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.GrpcEnvironment.AddRef () [0x00028] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Channel..ctor (System.String target, Grpc.Core.ChannelCredentials credentials, System.Collections.Generic.IEnumerable`1[T] options) [0x00051] in <2f154ad39ec14cfea604815989d96352>:0
    at Grpc.Core.Channel..ctor (System.String target, Grpc.Core.ChannelCredentials credentials) [0x00000] in <2f154ad39ec14cfea604815989d96352>:0
    at Unity.MLAgents.RpcCommunicator.Initialize (Unity.MLAgents.CommunicatorObjects.UnityOutputProto unityOutput, Unity.MLAgents.CommunicatorObjects.UnityInputProto& unityInput) [0x00008] in \Library\PackageCache\com.unity.ml-agents@1.6.0-preview\Runtime\Communicator\RpcCommunicator.cs:213
    at Unity.MLAgents.RpcCommunicator.Initialize (Unity.MLAgents.CommunicatorInitParameters initParameters) [0x00041] in \Library\PackageCache\com.unity.ml-agents@1.6.0-preview\Runtime\Communicator\RpcCommunicator.cs:120
    UnityEngine.Debug:LogError(Object)
    Unity.MLAgents.RpcCommunicator:Initialize(CommunicatorInitParameters) (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Communicator/RpcCommunicator.cs:163)
    Unity.MLAgents.Academy:InitializeEnvironment() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Academy.cs:426)
    Unity.MLAgents.Academy:LazyInitialize() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Academy.cs:266)
    Unity.MLAgents.Academy:.ctor() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Academy.cs:236)
    Unity.MLAgents.<>c:<.cctor>b__83_0() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Academy.cs:105)
    System.Lazy`1:get_Value()
    Unity.MLAgents.Academy:get_Instance() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/Academy.cs:120)
    Unity.MLAgents.DecisionRequester:Awake() (at Library/PackageCache/com.unity.ml-agents@1.6.0-preview/Runtime/DecisionRequester.cs:49)


    After searching the internet I found this thread https://github.com/grpc/grpc/issues/21550 suggesting installing the newset c++ redistributables, which didn't help either. There are other threads with the same problem (1, 2), but I think they have a genral problem. The other project is still working fine so it can't be a general problem, it has to be project specific. I Tried every mlagents version up to 2.1.0 which does display the error itself without the need to debug into the code. I tried to copy the packages from the Library folder of the project where it is working but without any success.

    So my question is, what differnces can there be in projects that lead to this behaviour where one works like a charme and the other doesn't?

    EDIT:
    I just created a complete blank project with the same specs and it works without any issues.
    The only differnce I can find is that the project not working is using in the .csproj file the refernces from the "MonoBleedingEdge/lib/mono/4.7.1-api" location for the .net dlls and the other two project using the "NetStandard/compat/2.0.0/shims" location.
     
    Last edited: Jun 24, 2021
  2. Gistiv

    Gistiv

    Joined:
    Apr 22, 2014
    Posts:
    13
    After 12h+ I've found the issue. There was a 'ß' in my projects name and therefore also in the path to that library... Same for 'ä, ö, ü' i guess. This is that tyoe of problem only Germans have to deal with.
     
    ervteng_unity likes this.
  3. sascharo

    sascharo

    Joined:
    Sep 17, 2021
    Posts:
    7
    Wow, I have to give this a try.
     
  4. sascharo

    sascharo

    Joined:
    Sep 17, 2021
    Posts:
    7
    Haha, it worked! My Unity project had a "–" instead of "-" in the filename.