Cysharp / YetAnotherHttpHandler

YetAnotherHttpHandler brings the power of HTTP/2 (and gRPC) to Unity and .NET Standard.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using YetAnotherHttpHandler in an asmdef

Baudin999 opened this issue · comments

Hi, I am trying to add YetAnotherHttpHandler to my asmdef does anyone have a working example?

I went through the installation process and everything worked perfectly, now when I am structuring my project and I have a Networking.asmdef folder in which I place my code, the compiler cannot find the namespace Cysharp.Net.Http anymore. When I move the code file out of my asmdef, everything works again.

This is the code:

using System.Collections.Concurrent;
using Cysharp.Net.Http;
using Grpc.Net.Client;

public static class NetworkingHelpers {
    
    static ConcurrentDictionary<string, GrpcChannel> _channels = new();
    
    public static GrpcChannel CreateGrpcClient(string address) {
        
        if (_channels.TryGetValue(address, out var cachedChannel)) {
            return cachedChannel;
        }
        
        var httpHandler = new YetAnotherHttpHandler();
        var channel = GrpcChannel.ForAddress("", new() { HttpHandler = httpHandler });
        _channels.TryAdd(address, channel);

        return channel;
    }
}

I was able to reproduce:

Create the following folders:
Assets > Scripts > Networking

  • Create file NetworkingHelpers with the code above

Everything should work, compile and feel beautiful.

Now add the file networking.asmdef and it breaks.

I have tried adding references of the dependencies, but to no avail. Is this a known limitation? Or am I doing something wrong?

You don't provide the content of your networking.asmdef but it needs to have reference to assembly named Cysharp.Net.Http.YetAnotherHttpHandler.

Thank you so much, it works, really don't know what I did wrong, I hade the following asmdef:

{
  "name": "Networking",
  "references": [
    "Cysharp.Net.Http.YetAnotherHttpHandler",
     ....
  ]
}

It didn't work then, it works perfectly now. Thank you so much!