Problem calling .NET DLL from Visual Fox Pro

I have the following method that calls a .NET DLL from VFP.

n=0
ON ERROR n=1
x = createobject("Business_Bancos.ApiKhipu_Bancos")
if n=0
   ON error
    &&respuesta=x.prueba()
    respuesta=x.obtienerespuestakhipu(tipobanco, host, userNamebd, dataBase, puerto, passworddb, valor_banco, UserName, Password, EnterpriseIdentity, Role, Agreement, accountNumber, BookingDateStart, BookingDateEnd)
    result=respuesta.datos


else
   messagebox("Error....!!",16,"Aviso")
ENDIF

And in the .net dll, I call the method as follows:

  public async Task<Respuesta> obtienerespuestakhipu(string tipobanco,
        string host,
        string user,
        string dataBase,
        string puerto,
        string passworddb,
        string codigobanco,
        string UserName,
        string Password,
        string EnterpriseIdentity,
        string Role,
        string Agreement,
        string accountNumber,
        string BookingDateStart,
        string BookingDateEnd)
    {
        string url_acount = "";
        string api_key = "";
        Clase_Conexion conexion = new Clase_Conexion(host, user, dataBase, puerto, passworddb);
        string respuesta = "";
        Respuesta resp = new Respuesta(); 
        url_acount = await ObtieneAccountLink_BancoPersonal(api_key, UserName, Password, urlbanco_accountlink);
                         
    }


    public async Task<string> ObtieneAccountLink_BancoPersonal(string api_key, string UserName, string Password, string urlbanco)
    {
        string accountLink = "";
        var serviceCollection = new ServiceCollection();
        Configuere(serviceCollection);
        var servicios = serviceCollection.BuildServiceProvider();
        var httpClientFactory = servicios.GetRequiredService<IHttpClientFactory>();
        var client = httpClientFactory.CreateClient();
        client.DefaultRequestHeaders.Add("x-api-key", api_key);

        String str_json = "{\"Username\":'" + UserName + "',\"Password\":'" + Password + "'}";
        JObject json = JObject.Parse(str_json);
        MessageBox.Show(urlbanco);
        var postData = new StringContent(json.ToString(), Encoding.UTF8, "application/json");
        //se cae
        var request = await client.PostAsync(urlbanco, postData);

            ..........

    }

And following up, it falls into the following line of code:

  var request = await client.PostAsync(urlbanco, postData);

When using the asynchronous method, I get an error from VFP, when calling the .NET DLL. The error it gives is the following:

An exception occurred in the log type type initializer

Does anyone have any idea how to solve it?

  • Please write your title in English.

    – 

  • BTW, your code will fail if the user’s username or password contains a " character.

    – 

  • can you post the constructor for whatever class having that ObtieneAccount...? did you use any logging tools? are they initialized properly?

    – 

  • 3

    Because you’re trying to call a Task-returning async method from a COM consumer, you’re going to have problems getting any continuation to work – the only alternative I can think of means you’d need to add a non-Task wrapper method which uses a callback parameter and passes that into .ContinueWith – and I have no idea if FoxPro even supports that… EDIT: Ah, to support COM clients you’ll need to expose an IAsyncResult-compatible APIhave fun

    – 




  • @BagusTesa Edit the question where I called, I failed to include the intermediate method obtainanswerkhipu that calls the GetAccountLink_BancoPersonal method

    – 

Leave a Comment