Describe the bug
Any project that uses IAsyncEnumerable<T> with ML-Agents imported and .NET Standard 2.1 enabled will cause compiler errors.
Context
The type System.Collections.Generic.IAsyncEnumerable<T> is available in both the included System.Interactive.Async assembly (which is used by Grpc.Core) and in .NET Standard 2.1. Since around Unity 2021.3, Unity includes IAsyncEnumerable<T> as part of its .NET Standard 2.1 support; as a consequence, the compiler can't decide whether to import IAsyncEnumerable<T> from netstandard or from System.Interactive.Async.
This issue probably occurs with other types in System.Interactive.Async, but I only checked this one.
To Reproduce
- Install ML-Agents
- Write or install any code that uses
IAsyncEnumerable<T> (in my case, this package)
- Let the Unity editor try to compile your project.
Console logs / stack traces
It depends on the exact library, but here's an example from Razensoft.Mapper:
[CompilerError] The type 'IAsyncEnumerable<T>' exists in both 'System.Interactive.Async, Version=3.0.1000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' and 'netstandard, Version=2.1.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'
Compiler Error at Library\PackageCache\com.razensoft.mapper@1.0.4\Runtime\Extensions\MapEnumerableAsync.cs:26 column 13
24: public static async IAsyncEnumerable<TDestination> MapEnumerableAsync<TSource, TDestination>(
25: this IMapper<TSource, TDestination> mapper,
-->26: IAsyncEnumerable<TSource> source,
27: [EnumeratorCancellation] CancellationToken cancellationToken = default)
28: where TDestination : new()
Environment:
- Unity Version: 2022.1.19f1
- OS + version: Windows 10
- ML-Agents version: 2.3.0-exp.2
- Torch version: Not relevant
- Environment: Not relevant
Proposed Fix
I see a couple of possible fixes:
- Add the define constraint
!NET_STANDARD_2_1 to the included System.Interactive.Async assembly. This way, Grpc.Core will use netstandard when available.
- Disable auto-referencing in
System.Interactive.Async. Grpc.Core can continue to use that library this way, if you don't mind pulling in redundant library code.
Workaround
I see two workarounds:
- Modify ML-Agents with the aforementioned proposed fix. (This worked for me.)
- Manually override references in any assembly definition that uses APIs offered by
System.Interactive.Async, such that these asmdefs don't seek it out. (This also worked, but you'd have to do it for every offending assembly.)
Describe the bug
Any project that uses
IAsyncEnumerable<T>with ML-Agents imported and .NET Standard 2.1 enabled will cause compiler errors.Context
The type
System.Collections.Generic.IAsyncEnumerable<T>is available in both the includedSystem.Interactive.Asyncassembly (which is used byGrpc.Core) and in .NET Standard 2.1. Since around Unity 2021.3, Unity includesIAsyncEnumerable<T>as part of its .NET Standard 2.1 support; as a consequence, the compiler can't decide whether to importIAsyncEnumerable<T>fromnetstandardor fromSystem.Interactive.Async.This issue probably occurs with other types in
System.Interactive.Async, but I only checked this one.To Reproduce
IAsyncEnumerable<T>(in my case, this package)Console logs / stack traces
It depends on the exact library, but here's an example from Razensoft.Mapper:
Environment:
Proposed Fix
I see a couple of possible fixes:
!NET_STANDARD_2_1to the includedSystem.Interactive.Asyncassembly. This way,Grpc.Corewill usenetstandardwhen available.System.Interactive.Async.Grpc.Corecan continue to use that library this way, if you don't mind pulling in redundant library code.Workaround
I see two workarounds:
System.Interactive.Async, such that theseasmdefs don't seek it out. (This also worked, but you'd have to do it for every offending assembly.)