hazzik / DelegateDecompiler

A library which is able to decompile a delegate or a method body to its lambda representation
MIT License
522 stars 62 forks source link

Could not load type 'Microsoft.EntityFrameworkCore.Query.Internal.IAsyncQueryProvider' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. #161

Closed SOHODeveloper closed 3 years ago

SOHODeveloper commented 3 years ago

I am running .net core 5.0 preview 7.

I have the following extension method

    public static Task<List<TModel>> ProjectToListAsync<TModel> (this IQueryable target, IConfigurationProvider config,
      CancellationToken cancellationToken)
    {
      var a = target.ProjectTo<TModel>(config);
      var b = a.DecompileAsync();
      var c = b.ToListAsync(cancellationToken);
      return c;
      //      return target.ProjectTo<TModel>(config).DecompileAsync().ToListAsync(cancellationToken);
}

The ProjectTo() is from AutoMapper in the AutoMapper.QueryableExtensions namespace As written the line b = a.DecompileAsync() causes the following exception.

System.TypeLoadException: Could not load type 'Microsoft.EntityFrameworkCore.Query.Internal.IAsyncQueryProvider' from assembly 'Microsoft.EntityFrameworkCore, Version=5.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.
   at DelegateDecompiler.EntityFrameworkCore.DecompileExtensions.DecompileAsync[T](IQueryable`1 self)
   at STS.Data.Access.IQueryableExtensionClass.ProjectToListAsync[TModel](IQueryable target, IConfigurationProvider config, CancellationToken cancellationToken) in C:\Third Party Sources\STS\Foundation\Data\Access\Extensions\IQueryableExtensionClass.cs:line 63
   at Sequium.David.Platform.Data.Access.Repositories.CfgEmailRepository.FindProcessesToRunAsync(TimeSpan firstTime, TimeSpan lastTime, CancellationToken cancellationToken) in C:\Development\Common\David Platform\Data\Access\Repositories\CfgEmailRepository.cs:line 94
   at Sequium.David.Platform.DbTester.Program.RunAsync(String[] args) in C:\Development\Common\David Platform\DBTester\Program.cs:line 151

If I change the DecompileAsync() to Decompile(), the next line throws and indicates that b is not an IAsyncEnumberable.

I will be perfectly honest, that a lot of this is over my head, but I have confirmed that EntityFrameCore dll is present and have used it in a non-async query just 2 lines before calling my extension method.

Thanks for this great package.

nphmuller commented 3 years ago

This project doesn't support EF Core 5 yet. The namespace of IAsyncQueryProvider changed between EFCore 3.1 and EFCore 5. Since this project is still searching for it via its 3.1 namespace you get the error you mentioned, using this project with EFCore 5.

On a happier note: a PR has been opened to add support for EFCore 5 (https://github.com/hazzik/DelegateDecompiler/pull/164). Once that gets merged everything should just work!

hazzik commented 3 years ago

As per @nphmuller EF Core 5.0 is not yet supported.

hazzik commented 3 years ago

Please use DelegateDecompiler.EntityFramework5 package.