0 votes

I'm using a C# SDK (called MyGeotab) within Godot for a research project that I'm part of. I've verified that the (essentially) identical code works in a non-Godot context, but I get a pretty odd error when I use it within Godot. I've tried to change my .csproj variables to ensure consistency, but nothing has fixed the issue or changed it at all. The exception in question happens and is caught when awaiting an asynchronous authentication call to the API,


System.TypeInitializationException: The type initializer for 'Geotab.Checkmate.Web.WebServerInvoker' threw an exception. ---> System.NotImplementedException: The method or operation is not implemented.
at System.Net.Http.MonoWebRequestHandler.setMaxConnectionsPerServer (System.Int32 value) [0x00000] in :0
at System.Net.Http.HttpClientHandler.set
MaxConnectionsPerServer (System.Int32 value) [0x00000] in :0
at Geotab.Checkmate.Web.WebServerInvoker..cctor () [0x00025] in <9148131229b244b7aa2bce90144668f3>:0
--- End of inner exception stack trace ---
at Geotab.Checkmate.Web.MyServerInvoker..ctor (System.String url, System.Nullable`1[T] timeout, System.String servicePath, System.Net.Http.HttpMessageHandler handler) [0x00016] in <9148131229b244b7aa2bce90144668f3>:0
at Geotab.Checkmate.API.AuthenticateImplAsync (System.Threading.CancellationToken cancellationToken) [0x00030] in <9148131229b244b7aa2bce90144668f3>:0
at Geotab.Checkmate.API.AuthenticateAsync (System.Threading.CancellationToken cancellationToken) [0x00085] in <9148131229b244b7aa2bce90144668f3>:0
at APINode.<_Process>b__5_0 () [0x0003c] in C:\Users\rholm\Desktop\Research2021UMD\scripts\APINode.cs:99

In short, what I believe is happening is that the dependency stack that Godot uses is providing some different HTTP request stuff and it's screwing with this SDK's algorithm. I can't prove this with my rather light experience with both C# and this SDK, that's why I'm here.

The code that I'm running that produces this error is as follows. There's other stuff running but it should not be interfering with this node at all, although I may try it in a separate project to see if that changes anything. The code that I'm running has a username and password in it, so I've intentionally replaced that with ~'s.

The error is occurring on the bolded line, await data.api.AuthenticateAsync(); which is where the authentication call to the API is made.


    using Godot;
    using Geotab.Checkmate;
    using Geotab.Checkmate.ObjectModel;
    using System.Collections.Generic;
    using System.Threading.Tasks;
     
    public class APINode : Node
    {
     
        class GeotabData
        {
     
            private string UserName, Password, Database, Server;
            private Geotab.Checkmate.API API;
     
            public Geotab.Checkmate.API api
            {
                get
                {
                    return API;
                }
            }
     
            public GeotabData(string userName, string password, string database, string server = "") //"my.geotab.com"
            {
                UserName = userName;
                Password = password;
                Database = database;
                Server = server;
                GD.Print(UserName);
                GD.Print(Password);
                GD.Print(Database);
                GD.Print(Server);
                API = new API(UserName, Password, null, Database);
            }
     
            public async Task Init()
            {
                await API.AuthenticateAsync();
            }
     
            public async Task Test()
            {
     
                // Get all devices
                var devices = await API.CallAsync>("Get", typeof(Device));
                GD.Print("Name\t\tSerialNumber\tLatitude\tLongitude\tSpeed");
                foreach (Device device in devices)
                {
                    // Get the Device Status Info which contains the current latitude and longitude for this device
                    var results = await API.CallAsync>("Get", typeof(DeviceStatusInfo), new
                    {
                        search = new DeviceStatusInfoSearch
                        {
                            DeviceSearch = new DeviceSearch
                            {
                                Id = device.Id
                            }
                        }
                    });
     
                    if (results.Count <= 0)
                    {
                        continue;
                    }
     
                    DeviceStatusInfo deviceStatus = results[0];
     
                    // Print the results to the console
                    GD.Print(device.Name.PadRight(12) + "\t"
                        + device.SerialNumber + "\t"
                        + deviceStatus.Latitude + "\t"
                        + deviceStatus.Longitude + "\t"
                        + deviceStatus.Speed);
                }
            }
        }
     
        GeotabData data;
        Task task = null;
     
        public override void _Ready()
        {
            GD.Print("In Ready");
     
            data = new GeotabData("~~~~~~~~", "~~~~~~~", "~~~~~~~");
        }
     
        // Called every frame. 'delta' is the elapsed time since the previous frame.
        bool ran = false;
        public override void _Process(float delta)
        {
            if (!ran)
            {
                Task.Run(async () =>
                {
                    try
                    {
                        await data.api.AuthenticateAsync();
                    }
                    catch (System.Exception e)
                    {
                        GD.Print(e);
                    }
     
                    return Task.CompletedTask;
                });
                ran = true;
            }
        }
    }
Godot version 3.3.4-mono
in Engine by (12 points)

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.