Repository: dotnet/orleans

Issue #7284: With the new feature 'global using' (C# 10) causes problem for the code generator
Created: 2021-09-20T16:47:43Z
Hi,
The code generator is having problem with source code created with C# 10 (Visual Studio 2022 preview). The problem seem to be that the code generator depends on the using System.Threading.Tasks declaration in the file.
The System.Threading.Tasks namespace is implicitly imported with C# 10, so declarations with Task works without the explicit using System.Threading.Tasks (but now the code generator generates an error because the namespace was missing).
For example:
using Orleans;

namespace Test
{
    public interface IMyGrain : IGrainWithStringKey
    {
        Task<long> Add(long a, long b);
    }
}

Displays the error:
Exc level 0: System.InvalidOperationException: Grain interface Test.IMyGrain has method Test.IMyGrain.Add(long, long) which returns a non-awaitable type Task<long>. All grain interface methods must return awaitable types. Did you mean to return Task<Task<long>>?
The workaround is simply to declare the namespace explicitly:
using Orleans;

#pragma warning disable IDE0005
// Orleans code generator need this declaration ('System.Threading.Tasks' is included implicitly by compiler with C# 10)
using System.Threading.Tasks;

namespace Test
{
    public interface IMyGrain : IGrainWithStringKey
    {
        Task<long> Add(long a, long b);
    }
}

The disable warning pragma is used to get rid of intellisense suggestion about removing the using (the code cleanup removes the using statement anyway though...).

Duplicate issue #7365: Code generation fails on .NET 6 RC2 with code generator judging Task not awaitable
Created: 2021-10-31T02:14:11Z
Attempting to build an ASP.NET Core 6 app (.NET 6 RC2, Blazor WebAssembly template) with Orleans 3.5.0 (using Microsoft.Orleans.CodeGenerator.MSBuild) fails with generator incorrectly reporting using non-awaitable type for the interface method.
1>------ Build started: Project: Lobbyist.Server, Configuration: Debug Any CPU ------
1>You are using a preview version of .NET. See: https://aka.ms/dotnet-core-preview
1>Orleans.CodeGenerator - command-line = SourceToSource C:\Users\Goric\source\repos\Lobbyist\Lobbyist\Lobbyist.Server\obj\Debug\net6.0\Lobbyist.Server.orleans.g.args.txt
1>fail: Orleans.CodeGenerator[0]
1>      Grain interface Lobbyist.Server.Game.GrainInterfaces.IGameGrain has method Lobbyist.Server.Game.GrainInterfaces.IGameGrain.AddPlayer(Lobbyist.Server.Game.GrainInterfaces.IPlayerGrain) which returns a non-awaitable type Task. All grain interface methods must return awaitable types. Did you mean to return Task<Task>?
1>-- Code Generation FAILED --
1>
1>Exc level 0: System.InvalidOperationException: Grain interface Lobbyist.Server.Game.GrainInterfaces.IGameGrain has method Lobbyist.Server.Game.GrainInterfaces.IGameGrain.AddPlayer(Lobbyist.Server.Game.GrainInterfaces.IPlayerGrain) which returns a non-awaitable type Task. All grain interface methods must return awaitable types. Did you mean to return Task<Task>?
1>   at Orleans.CodeGenerator.Analysis.CompilationAnalyzer.InspectGrainInterface(INamedTypeSymbol type) in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator\Analysis\CompilationAnalyzer.cs:line 193
1>   at Orleans.CodeGenerator.Analysis.CompilationAnalyzer.InspectType(INamedTypeSymbol type) in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator\Analysis\CompilationAnalyzer.cs:line 264
1>   at Orleans.CodeGenerator.CodeGenerator.AnalyzeCompilation() in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator\CodeGenerator.cs:line 78
1>   at Orleans.CodeGenerator.MSBuild.CodeGeneratorCommand.Execute(CancellationToken cancellationToken) in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator.MSBuild\CodeGeneratorCommand.cs:line 148
1>   at Microsoft.Orleans.CodeGenerator.MSBuild.Program.SourceToSource(String[] args) in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator.MSBuild\Program.cs:line 138
1>   at Microsoft.Orleans.CodeGenerator.MSBuild.Program.Main(String[] args) in D:\build\agent\_work\31\s\src\Orleans.CodeGenerator.MSBuild\Program.cs:line 26
1>C:\Users\Goric\.nuget\packages\microsoft.orleans.codegenerator.msbuild\3.5.0\build\Microsoft.Orleans.CodeGenerator.MSBuild.targets(125,5): error MSB3073: The command ""dotnet" "C:\Users\Goric\.nuget\packages\microsoft.orleans.codegenerator.msbuild\3.5.0\build\..\tasks\netcoreapp3.1\Orleans.CodeGenerator.MSBuild.dll" SourceToSource "C:\Users\Goric\source\repos\Lobbyist\Lobbyist\Lobbyist.Server\obj\Debug\net6.0\Lobbyist.Server.orleans.g.args.txt"" exited with code 3.
1>Done building project "Lobbyist.Server.csproj" -- FAILED.

IGameGrain code:
using Orleans;

namespace Lobbyist.Server.Game.GrainInterfaces
{
    public interface IGameGrain : IGrainWithGuidKey
    {
        Task AddPlayer(IPlayerGrain player);
    }
}

Closing comment (2021-10-31T02:20:53Z): Closing, this is a duplicate of #7284.