System.TypeLoadException: 'Could not load type 'Microsoft.EntityFrameworkCore.Query.Internal.IAsyncQueryProvider' from assembly 'Microsoft.EntityFrameworkCore, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'
NullReferenceException is thrown with the following stacktrace when you initialize QueryableEntityCoreCollectionView.
at Telerik.Windows.Data.QueryableProxy`1.get_Count() at Telerik.Windows.Data.QueryableEntityCoreCollectionView`1.UpdateTotalItemCount() at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable sourceCollection, Type itemType) at Telerik.Windows.Data.QueryableCollectionView..ctor(IEnumerable source) at Telerik.Windows.Data.QueryableEntityCoreCollectionView`1..ctor(DbContext dbContext, IQueryable`1 query, Collection`1 include)
To work this around, you can create a custom QueryableEntityCoreCollectionView class and override its UpdateTotalItemCount() method.
public class CustomQueryableEntityCoreCollectionView<T> : QueryableEntityCoreCollectionView<T> where T : class, new()
{
public CustomQueryableEntityCoreCollectionView(DbContext dbContext, IQueryable<T> query, Collection<string> include)
: base(dbContext, query, include)
{
}
protected override void UpdateTotalItemCount()
{
var sourceListProperty = typeof(QueryableCollectionView).GetProperty("SourceList", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var sourceList = (IList)sourceListProperty.GetValue(this);
if (sourceList != null && !(sourceList is ICollectionView))
{
this.TotalItemCount = sourceList.Count;
}
else
{
var proxyProperty = typeof(QueryableEntityCoreCollectionView<T>).GetProperty("Proxy", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
var proxy = proxyProperty.GetValue(this);
if (proxy != null)
{
var dbSetProperty = proxy.GetType().GetProperty("DbSet");
var dbSet = dbSetProperty.GetValue(proxy) as DbSet<T>;
if (dbSet != null)
{
this.TotalItemCount = dbSet.Local.Count;
}
else
{
this.TotalItemCount = this.QueryableSourceCollection.Count();
}
}
}
}
}