influxdb-client-csharp icon indicating copy to clipboard operation
influxdb-client-csharp copied to clipboard

Adding support to run in blazor wasm ?

Open intech-paul opened this issue 4 years ago • 3 comments

I am trying to get the client db api to run in a blazor app and am getting a platform not supported error, are you planning to allow the library to work with blazor web assembly ?

` var influxDBClient = InfluxDBClientFactory.Create("https://us-west-2-1.aws.cloud2.influxdata.com/", Token);

    int i = 0;

    var fluxTables = await influxDBClient.GetQueryApi().QueryAsync(flux, orgid);
    fluxTables.ForEach(fluxTable =>
    {
        var fluxRecords = fluxTable.Records;
        fluxRecords.ForEach(fluxRecord =>
        {
            Console.WriteLine(i + "\t" + $"{fluxRecord.GetTime()}\t{fluxRecord.GetValue()}\t{fluxRecord.GetValueByIndex(8)}");
            i++;
        });
    });

`

intech-paul avatar May 04 '20 03:05 intech-paul

Hi @intech-paul,

The Blazor doesn't have a full support of netstandard2.0:

APIs that aren't applicable inside of a web browser (for example, accessing the file system, opening a socket, and threading) throw a PlatformNotSupportedException.

https://docs.microsoft.com/cs-cz/aspnet/core/blazor/?view=aspnetcore-3.1#code-sharing-and-net-standard

So I thing there is no easy way how to add supports for blazor, but definitely we want to support a whole dotnet stack.

Is this something you might be willing to help with?

Regards

bednar avatar May 04 '20 07:05 bednar

Hi, I think this is beyond my experience level.

The exception that is thrown is:

Operation is not supported on this platform. at RestSharp.RestClient.DownloadData (RestSharp.IRestRequest request, System.Boolean throwOnError) <0x38203e8 + 0x00040> in :0 at InfluxDB.Client.Core.Internal.AbstractQueryClient+<>c__DisplayClass8_0.<Query>b__1 () <0x38201b8 + 0x00016> in :0 at System.Threading.Tasks.Task.InnerInvoke () <0x38200b0 + 0x00020> in :0 at System.Threading.Tasks.Task.Execute () <0x32c1d70 + 0x00008> in :0 --- End of stack trace from previous location where exception was thrown --- at InfluxDB.Client.Core.Internal.AbstractQueryClient+<>c.<.cctor>b__19_1 (System.Exception e) <0x38a0a00 + 0x00004> in :0 at InfluxDB.Client.Core.Internal.AbstractQueryClient.Query (RestSharp.RestRequest query, System.Action2[T1,T2] consumer, System.Action1[T] onError, System.Action onComplete) <0x38112c8 + 0x0023a> in :0 at InfluxDB.Client.Core.Internal.AbstractQueryClient.Query (RestSharp.RestRequest query, InfluxDB.Client.Core.Flux.Internal.FluxCsvParser+IFluxResponseConsumer responseConsumer, System.Action1[T] onError, System.Action onComplete) <0x3809478 + 0x00122> in <filename unknown>:0 at InfluxDB.Client.QueryApi.QueryAsync (InfluxDB.Client.Api.Domain.Query query, System.String org, InfluxDB.Client.Core.Flux.Internal.FluxCsvParser+IFluxResponseConsumer consumer, System.Action1[T] onError, System.Action onComplete) <0x34e0ff8 + 0x00142> in :0 at InfluxDB.Client.QueryApi.QueryAsync (InfluxDB.Client.Api.Domain.Query query, System.String org) <0x34de1a8 + 0x00108> in :0 at InfluxDB.Client.QueryApi.QueryAsync (System.String query, System.String org) <0x34dcd80 + 0x00100> in :0 at BlazorInfluxTest2.Shared.ReadData.Read () [0x0008d] in C:\Users\xxxx\source\repos\BlazorInfluxTest2\BlazorInfluxTest2\Shared\ReadData.cs:35

I would guess that this is because RestSharp.RestClient is not using HtppClient which is supported on blazor.

There is a item already mentioned for this in RestSHarp: https://github.com/restsharp/RestSharp/issues/1406

intech-paul avatar May 04 '20 21:05 intech-paul

Thanks for detail info.

Yeah RestSharp is a source of problem 😞 .

Unfortunately OpenApi generators uses RestSharp as a http client. We could try use a https://github.com/RicoSuter/NSwag but currently we don't have a time-plan for that.

bednar avatar May 05 '20 06:05 bednar