Cysharp / YetAnotherHttpHandler

YetAnotherHttpHandler brings the power of HTTP/2 (and gRPC) to Unity and .NET Standard.
MIT License
376 stars 33 forks source link

Using YetAnotherHttpHandler in an asmdef #37

Closed Baudin999 closed 9 months ago

Baudin999 commented 11 months ago

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

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?

mangolas commented 10 months ago

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

Baudin999 commented 9 months ago

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!