IAsyncQueryProvider build errors after migrating to .Net Core v3.1

.net asp.net async-await c# entity-framework-core

Question

After migrating a project from .NET Core 2.2 to version 3.1 I got an error with IAsyncEnumerator & IAsyncQueryProvider:

  1. The type 'IAsyncEnumerable' exists in both 'System.Interactive.Async, Version=3.0.3000.0, Culture=neutral, PublicKeyToken=94bc3704cddfc263' and 'System.Runtime, Version=4.2.2.0
  2. 'TestAsyncQueryProvider' does not implement interface member 'IAsyncQueryProvider.ExecuteAsync(Expression)'. 'TestAsyncQueryProvider.ExecuteAsync(Expression)' cannot implement 'IAsyncQueryProvider.ExecuteAsync(Expression)' because it does not have the matching return type of 'IAsyncEnumerable'.

I managed to resolve the first issue related to IAsyncEnumerable with this fix below which I found on google:

  <Target Name="ChangeAliasesOfReactiveExtensions" BeforeTargets="FindReferenceAssembliesForReferences;ResolveReferences">
    <ItemGroup>
      <ReferencePath Condition="'%(FileName)' == 'System.Interactive.Async'">
        <Aliases>ix</Aliases>
      </ReferencePath>
    </ItemGroup>
  </Target>

However, I cannot find any solutions for the second issue.

Code example where I am getting an error:

internal class TestAsyncQueryProvider<TEntity> : IAsyncQueryProvider
    {
        private readonly IQueryProvider _inner;

        internal TestAsyncQueryProvider(IQueryProvider inner)
        {
            _inner = inner;
        }

        public IQueryable CreateQuery(Expression expression)
        {
            return new TestAsyncEnumerable<TEntity>(expression);
        }

        public IQueryable<TElement> CreateQuery<TElement>(Expression expression)
        {
            return new TestAsyncEnumerable<TElement>(expression);
        }

        public object Execute(Expression expression)
        {
            return _inner.Execute(expression);
        }

        public TResult Execute<TResult>(Expression expression)
        {
            return _inner.Execute<TResult>(expression);
        }

        public IAsyncEnumerable<TResult> ExecuteAsync<TResult>(Expression expression)
        {
            return new TestAsyncEnumerable<TResult>(expression);
        }

        public Task<TResult> ExecuteAsync<TResult>(Expression expression, CancellationToken cancellationToken)
        {
            return Task.FromResult(Execute<TResult>(expression));
        }
    }

I wonder if anyone had similar issues and managed to resolve them. Also, worth mentioning, that I am still using EF Core v2.x and haven't migrated it to version 3 yet.

1
0
2/14/2020 3:49:48 PM

Popular Answer

The interface for Execute was replaced with ExecuteAsync in the IdentityServer update.

There is a library that has successfully upgraded this mock implementation to .NET Core 3.0:

https://github.com/romantitov/MockQueryable/blob/master/src/MockQueryable/MockQueryable/TestAsyncEnumerable.cs

1
2/14/2020 4:13:36 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow