Search Unity

Question WebGL + GRPC does not work after build

Discussion in 'Web' started by RavidEliyahu, Mar 2, 2023.

  1. RavidEliyahu

    RavidEliyahu

    Joined:
    Jun 1, 2022
    Posts:
    1
    Hey guys,
    I wrote a GrpcService Class:
    Code (CSharp):
    1. using System.Net.Http;
    2. using System.Threading.Tasks;
    3. using Grpc.Core;
    4. using Nimbus.Core.Grpc;
    5. using Nimbus.Core.Grpc.WebApi;
    6. using Grpc.Net.Client;
    7. using Grpc.Net.Client.Web;
    8. using FileContentResponse;
    9.  
    10. public class GrpcService
    11. {
    12.     private readonly GrpcChannel _channel;
    13.     private const string PRODUCTION_SERVER_URL = "https://api.xxxxxx.com";
    14.  
    15.     public GrpcService(string token)
    16.     {
    17.         _channel = CreateAuthenticatedChannel(PRODUCTION_SERVER_URL, token);
    18.     }
    19.  
    20.     private GrpcChannel CreateAuthenticatedChannel(string address, string token)
    21.     {
    22.         var credentials = CallCredentials.FromInterceptor((_, metadata) =>
    23.         {
    24.             if (!string.IsNullOrEmpty(token))
    25.             {
    26.                 metadata.Add("Authorization", $"Bearer {token}");
    27.             }
    28.             return Task.CompletedTask;
    29.         });
    30.      
    31.         var channel = GrpcChannel.ForAddress(address, new GrpcChannelOptions
    32.         {
    33.             HttpHandler = new GrpcWebHandler(new HttpClientHandler()),
    34.             Credentials = ChannelCredentials.Create(new SslCredentials(), credentials),
    35.             MaxReceiveMessageSize = 1024 * 1024 * 50, // Set the maximum message size to 50 MB
    36.             MaxSendMessageSize = 1024 * 1024 * 50 // Set the maximum message size to 50 MB
    37.         });
    38.      
    39.         return channel;
    40.     }
    41.  
    42.     public FileContentResponse GetFileContentById(string id)
    43.     {
    44.         id = RemoveFilesSubstring(id);
    45.         var _filesServiceClient = new FilesService.FilesServiceClient(_channel);
    46.         var request = new IdRequest
    47.         {
    48.             Id = id
    49.         };
    50.  
    51.         return _filesServiceClient.GetFileContentById(request);
    52.     }
    53.  
    54.     private string RemoveFilesSubstring(string input)
    55.     {
    56.         int index = input.IndexOf("/files/");
    57.         return index >= 0 ? input.Substring(index + "/files/".Length) : input;
    58.     }
    59.  
    60.     private void OnDisable() {
    61.         _channel.ShutdownAsync().Wait();
    62.     }
    63. }
    I have successfully get response from my server using this class at the Editor level, but when I build I get the following error:
    Code (CSharp):
    1. Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. DllNotFoundException: Unable to load DLL 'libc'. Tried the load the following dynamic libraries: ", DebugException="System.DllNotFoundException: Unable to load DLL 'libc'. Tried the load the following dynamic libraries:
    2. ")
    I could not find any information or documentation regarding GRPC and WebGL...
    Any Ideas?
     
    Last edited: Mar 2, 2023
  2. unityruba

    unityruba

    Unity Technologies

    Joined:
    Nov 6, 2020
    Posts:
    270
    Unfortunately, you can't use .NET networking classes because JavaScript code doesn’t have direct access to IP Sockets to implement network connectivity, see the docs here to see what is available to you that's supported on WebGL.