Efcore: TypedRelationalValueBufferFactoryFactory throws TypeInitializationException

Created on 13 Mar 2019  路  10Comments  路  Source: dotnet/efcore

Describe what is not working as expected.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message: The type initializer for 'Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory' threw an exception.
Stack trace:
   at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.<>c__DisplayClass12_0.<CreateArrayInitializer>b__0(TypeMaterializationInfo mi, Int32 i)
   at System.Linq.Enumerable.SelectIterator[TSource,TResult](IEnumerable`1 source, Func`3 selector)+MoveNext()
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 items)
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 source)
   at System.Linq.Enumerable.ToArray[TSource](IEnumerable`1 source)
   at System.Dynamic.Utils.CollectionExtensions.ToReadOnly[T](IEnumerable`1 enumerable)
   at System.Linq.Expressions.Expression.NewArrayInit(Type type, IEnumerable`1 initializers)
   at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.CreateArrayInitializer(CacheKey cacheKey, Boolean detailedErrorsEnabled)
   at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.<Create>b__10_0(CacheKey k)
   at System.Collections.Concurrent.ConcurrentDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Storage.TypedRelationalValueBufferFactoryFactory.Create(IReadOnlyList`1 types)
   at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.CreateValueBufferFactory(IRelationalValueBufferFactoryFactory relationalValueBufferFactoryFactory, DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.<NotifyReaderCreated>b__14_0(FactoryAndReader s)
   at Microsoft.EntityFrameworkCore.Internal.NonCapturingLazyInitializer.EnsureInitialized[TParam,TValue](TValue& target, TParam param, Func`2 valueFactory)
   at Microsoft.EntityFrameworkCore.Query.Internal.ShaperCommandContext.NotifyReaderCreated(DbDataReader dataReader)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   (further stack trace is omitted)

Steps to reproduce

Include a complete code listing (or project/solution) that we can run to reproduce the issue.

Partial code listings, or multiple fragments of code, will slow down our response or cause us to push the issue back to you to provide code to reproduce the issue.

c# _ = (from a in _context.Set<T>().AsQueryable() select new { a.b, a.c }).ToList();

Further technical details

EF Core version: 3.0.0-preview3.19153.1
Database Provider: Npgsql.EntityFrameworkCore.PostgreSQL
Operating system: Microsoft Windows 10.0.18356
IDE: 16.0.28711.60

closed-fixed customer-reported type-bug

All 10 comments

This happens only on netcoreapp3.0, net48 is not affected.

> dotnet --version
3.0.100-preview4-010737

@KexyBiscuit Can you post the message and stack trace for the inner exception? Also, where did you install .NET Core 3.0 from and exactly which version did you install, and where did you install the EF packages from and exactly which version did you install? (The reason I am asking is this looks similar to something that happened in nightly builds, but we didn't think was in a preview release yet.)

@ajcvickers SDK is from core-sdk latest, version shown above, EF is exactly 3.0.0-preview3.19153.1.

@KexyBiscuit which version of Npgsql.EntityFrameworkCore.PostgreSQL are you using? Is this the recently-released 3.0.0-preview3? If not, please use that as its the only version that's supposed to be compatible with EF Core 3.0.0-preview3.19153.1.

@roji Yes, I'm using ci.1519 which is equivalent to preview3.

@KexyBiscuit I'm asking which version of Npgsql.EntityFrameworkCore.PostgreSQL you're using (there's no preview3.19153.1, only preview3), not which version of EF Core, can you please confirm?

@roji It's Npgsql.EntityFrameworkCore.PostgreSQL 3.0.0-preview3 / 3.0.0-ci.1519+sha.ba141fdde.

@KexyBiscuit This is expected with those versions. See https://github.com/dotnet/corefx/issues/31595. (A change to System.Data broke EF Core. EF Core has been fixed, but not in the preview3 release.) If you use the preview3 SDK with the preview3 EF Core, then I don't think you will hit this.

@KexyBiscuit if you use the officially released versions from nuget.org (rather than any CI/nightly builds), things should work fine.

EF Core has been fixed, but not in the preview3 release.

@ajcvickers What do you mean by fixed? I am using the latest EF build 3.0.0-preview4.19122.16 and still get this exception. (I have to use .NET Core nightly builds because of other bugfixes)

Was this page helpful?
0 / 5 - 0 ratings