-
Notifications
You must be signed in to change notification settings - Fork 169
SourceGenerator generates an error for IStreamRequest with structs #36
Copy link
Copy link
Closed
Description
Hi,
I tried converting one of my MediatR solutions to your source-gen approach and noticed the following:
The srcgen generates the following error for IStreamRequest with structs in 2.0.15-preview
Error CS0266 Cannot implicitly convert type 'System.Collections.Generic.IAsyncEnumerable<MyStruct>' to 'System.Collections.Generic.IAsyncEnumerable<object>'. An explicit conversion exists (are you missing a cast?) ConsoleApp7 Repro:
using Mediator;
public class Program
{
public static int Main(string[] args)
{
return 0;
}
}
public sealed class MyRequest : IStreamRequest<MyStruct>
{
}
public sealed class MyRequestHandler : IStreamRequestHandler<MyRequest, MyStruct>
{
public IAsyncEnumerable<MyStruct> Handle(MyRequest request, CancellationToken cancellationToken)
{
throw new NotImplementedException();
}
}
public readonly struct MyStruct
{
}The generated code snippet is:
/// <summary>
/// Create stream.
/// Throws <see cref="global::System.ArgumentNullException"/> if message is null.
/// Throws <see cref="global::Mediator.MissingMessageHandlerException"/> if no handler is registered.
/// </summary>
/// <param name="message">Incoming message</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>Async enumerable</returns>
public global::System.Collections.Generic.IAsyncEnumerable<object> CreateStream(
object message,
global::System.Threading.CancellationToken cancellationToken = default
)
{
switch (message)
{
case global::MyRequest m: return CreateStream(m, cancellationToken);
default:
{
ThrowArgumentNullOrInvalidMessage(message as global::Mediator.IStreamMessage, nameof(message));
return default;
}
}
}Workaround: use class instead of struct
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels