dotnet-sdk icon indicating copy to clipboard operation
dotnet-sdk copied to clipboard

Actor source generator does not copy generic constraints for type parameters

Open oising opened this issue 9 months ago • 4 comments

Expected Behavior

Given the following actor interface:

using Dapr.Actors.Generators;
using System.Threading.Tasks;

namespace Test
{
    public interface ITrait 
    {
        string GetName();
    }
    
    [GenerateActorClient]
    public interface ITestActor<TTrait> where TTrait : ITrait
    {
        Task<bool> SetTrait(TTrait trait);
        Task<TTrait> GetTrait(string name);
    }
}

it should generate a class definition like this:

public sealed class TestActorClient<TTrait> : Test.ITestActor<TTrait> where TTrait : Test.ITrait
...

Actual Behavior

instead, it generates this:

public sealed class TestActorClient<TTrait> : Test.ITestActor<TTrait>
...

The constraints are not copied.

Steps to Reproduce the Problem

Use the DAPR source generator package with the above actor interface, then examine the analyzer output (or try to compile it.) It will fail.

Release Note

RELEASE NOTE:

oising avatar May 12 '25 17:05 oising

This is not of immediate use but is more for completeness since dapr dotnet actors currently forbid generic methods due to old service fabric limitiations (soap + datacontract serializer) but it would work with system.text.json serialization.

oising avatar May 13 '25 13:05 oising

Especially with the upcoming changes to the actor runtime to support streaming and pubsub, this might introduce a good opportunity to release a next-gen actors SDK that seeks to break from the older limitations and work with more generic serialization support. This isn't likely for the 1.16 release as it'd be a lot of work, but this is certainly worth keeping in mind.

WhitWaldo avatar May 13 '25 14:05 WhitWaldo

Especially with the upcoming changes to the actor runtime to support streaming and pubsub, this might introduce a good opportunity to release a next-gen actors SDK that seeks to break from the older limitations and work with more generic serialization support. This isn't likely for the 1.16 release as it'd be a lot of work, but this is certainly worth keeping in mind.

What do you mean next-get actor sdk? What is planned to change?

m3nax avatar May 19 '25 12:05 m3nax