dotnet/aspnetcore

HubClientProxyGenerator doesn't run when using inferred generic type arguments

Open

#43.510 geöffnet am 24. Aug. 2022

Auf GitHub ansehen
 (4 Kommentare) (0 Reaktionen) (1 zugewiesene Person)C# (10.653 Forks)batch import
area-signalrbughelp wanted

Repository-Metriken

Stars
 (37.933 Stars)
PR-Merge-Metriken
 (Durchschn. Merge 16T 9h) (258 gemergte PRs in 30 T)

Beschreibung

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

SignalR client proxy code isn't generated when using the extension method with auto-inferred type arguments (as suggested by Visual Studio).

Expected Behavior

The proxy code is generated.

Steps To Reproduce

Add Microsoft.AspNetCore.SignalR.Client.SourceGenerator package reference, add this code to a C# file:

using Microsoft.AspNetCore.SignalR.Client;

namespace ConsoleApp4;

internal static class Program
{
    static HubConnection hubConnection = null!;

    static void Main()
    {
        hubConnection = new HubConnectionBuilder().WithUrl("...").Build();
    }

    static void Register(IClient client)
    {
        // \/ Remove type argument here \/
        hubConnection.RegisterClient<IClient>(client);
    }
}

[AttributeUsage(AttributeTargets.Method)]
internal class HubServerProxyAttribute : Attribute
{
}

[AttributeUsage(AttributeTargets.Method)]
internal class HubClientProxyAttribute : Attribute
{
}

internal static partial class MyCustomExtensions
{
    [HubClientProxy]
    public static partial IDisposable RegisterClient<T>(this HubConnection connection, T provider);

    [HubServerProxy]
    public static partial T GetServerProxy<T>(this HubConnection connection);
}

public interface IServerHub
{
    Task SendMessage(string message);
}

public interface IClient
{
    Task ReceiveMessage(string message);
}

public class Client : IClient
{
    public Task ReceiveMessage(string message) => Task.CompletedTask;
}

then remove the generic type argument at line 18.

Contributor Guide