EF Core 2.1 Preview 1 throws MissingMethodException when using Pomelo.EntityFrameworkCore.MySql
After reading that EF Core 2.1 Preview 1 became available on Nuget, I wanted to if GroupBy SQL translation would just work using a 2.0 provider. My test didn't get far, however, and something as simple as ToListAsync throws an exception. Provider details are at the bottom.
The article stated:
Note that although there are a few features, such as value conversions, that require an updated database provider, existing providers developed for EF Core 2.0 should be compatible with EF Core 2.1. If there is any incompatibility, that is a bug we want to hear about!
That's why I am here.
Exception message:
System.MissingMethodException: 'Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)'.'
Stack trace:
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlCommandBuilder..ctor(IDiagnosticsLogger`1 logger, IRelationalTypeMapper typeMapper)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlCommandBuilderFactory.CreateCore(IDiagnosticsLogger`1 logger, IRelationalTypeMapper relationalTypeMapper)
at Microsoft.EntityFrameworkCore.Storage.Internal.MySqlCommandBuilderFactory.Create()
at Microsoft.EntityFrameworkCore.Query.Sql.DefaultQuerySqlGenerator.GenerateSql(IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Query.Internal.RelationalExpressionPrinter.CommandBuilderPrinter.TryPrintConstant(ConstantExpression constantExpression, IndentedStringBuilder stringBuilder, Boolean removeFormatting)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitConstant(ConstantExpression constantExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.VisitLambda[T](Expression`1 lambdaExpression)
at System.Linq.Expressions.Expression`1.Accept(ExpressionVisitor visitor)
at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Visit(Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.PrintInternal(Expression expression, Boolean removeFormatting, Nullable`1 characterLimit, Boolean highlightNonreducibleNodes)
at Microsoft.EntityFrameworkCore.Query.Internal.ExpressionPrinter.Print(Expression expression, Boolean removeFormatting, Nullable`1 characterLimit)
at Microsoft.EntityFrameworkCore.Internal.CoreLoggerExtensions.QueryExecutionPlanned(IDiagnosticsLogger`1 diagnostics, IExpressionPrinter expressionPrinter, Expression queryExecutorExpression)
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateExecutorLambda[TResults]()
at Microsoft.EntityFrameworkCore.Query.EntityQueryModelVisitor.CreateAsyncQueryExecutor[TResult](QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Storage.Database.CompileAsyncQuery[TResult](QueryModel queryModel)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQueryCore[TResult](Expression query, IQueryModelGenerator queryModelGenerator, IDatabase database)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass22_0`1.<CompileAsyncQuery>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQueryCore[TFunc](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddAsyncQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileAsyncQuery[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.System.Collections.Generic.IAsyncEnumerable<TResult>.GetEnumerator()
at System.Linq.AsyncEnumerable.<Aggregate_>d__6`3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
at ConsoleApp1.Program.<Main>d__0.MoveNext() in C:\Users\Adam\Desktop\MySqlCoreTesting\ConsoleApp1\Program.cs:line 42
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at ConsoleApp1.Program.<Main>(String[] args)
Steps to reproduce
public class ProjectDbContext : DbContext
{
public ProjectDbContext(DbContextOptions<ProjectDbContext> options)
: base(options) { }
public DbSet<Item> Items { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Item>()
.HasKey(i => i.Id);
modelBuilder.Entity<Item>()
.Property(p => p.Label)
.HasColumnType("text");
}
}
public class Item
{
public int Id { get; set; }
public string Label { get; set; }
}
// .Net Core 2.0 Console application
class Program
{
static async Task Main(string[] args)
{
DbContextOptionsBuilder<ProjectDbContext> builder = new DbContextOptionsBuilder<ProjectDbContext>();
builder.UseMySql("Your connection string.");
using (ProjectDbContext _dbContext = new ProjectDbContext(builder.Options))
{
await _dbContext.Items.ToListAsync();
}
}
}
Further technical details
EF Core version: "Microsoft.EntityFrameworkCore.Relational" Version="2.1.0-preview1-final" Database Provider: "Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" "MySqlConnector" Version="0.36.0" Operating system: Windows 10 16299.248 x64 IDE: Visual Studio 2017 15.5.7
@AdamDotNet Thanks for reporting this. It is happening because the MySQL provider is making use of EF Core internal code--I filed this issue for that: https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/issues/497
From the EF side, we will discuss in triage whether or not to revert this change to the internal code, but the long term solution is for the provider to stop using internal code.
@ajcvickers Thanks for pointing this out and writing up the issue with the PomeloFoundation!
Thanks for reporting this. I ran into this too and was getting ready to file an issue. I wasn't sure if providers would need to be updated to work with the new 2.1 update. Theoretically, minor revision number changes don't have breaking changes, but, I figured an update would probably be needed. The Npgsql provider seemed to have a different issue, but, luckily there is a preview release of that provider that fixed that issue.
I wonder if Oracle's MySQL provider works? I switched to Pomelo awhile back because Oracle was taking a long time getting their provider to work. Maybe it is better now.
@jemiller0 great to hear Npgsql is working ok for you on 2.1.0-preview1! Although it might be interesting what problem the 2.0 version of the provider had with the 2.1 version of the core.
@roji Thanks for the great work that you've been doing with the Npgsql providers. I know that I can always count on you to be right on top of things. You always seem to be in lockstep with the EF team at Microsoft. I was using the 2.0.1 provider and ran into the following exception. For some reason the Y in "p2"."actv_ind" = Y, wasn't quoted. When I upgraded to the 2.1.0 preview that you have, it worked fine. I just figured it was a known issue that you fixed.
OleLibrary Verbose: 0 : Executing DbCommand [Parameters=[@__id_0='?'], CommandType='Text', CommandTimeout='30']
SELECT "p2"."entity_id", "p2"."actv_ind", "p2"."obj_id", "p2"."last_updt_dt", "p2"."ver_nbr", "p2.PersonPrivacy"."entity_id", "p2.PersonPrivacy"."obj_id", "p2.PersonPrivacy"."last_updt_dt", "p2.PersonPri
vacy"."suppress_addr_ind", "p2.PersonPrivacy"."suppress_email_ind", "p2.PersonPrivacy"."suppress_nm_ind", "p2.PersonPrivacy"."suppress_prsnl_ind", "p2.PersonPrivacy"."suppress_phone_ind", "p2.PersonPriva
cy"."ver_nbr", "p2.PersonExt"."id", "p2.PersonExt"."chicago_id", "p2.PersonExt"."creation_time", "p2.PersonExt"."creation_user_name", "p2.PersonExt"."last_write_time", "p2.PersonExt"."last_write_user_nam
e", "p2.PersonExt"."staff_department", "p2.PersonExt"."staff_division", "p2.PersonExt"."staff_privileges", "p2.PersonExt"."staff_status", "p2.PersonExt"."status", "p2.PersonExt"."statuses", "p2.PersonExt
"."student_department", "p2.PersonExt"."student_division", "p2.PersonExt"."student_id", "p2.PersonExt"."student_restriction", "p2.PersonExt"."student_status", "p2.Patron"."ole_ptrn_id", "p2.Patron"."acti
vation_date", "p2.Patron"."actv_ind", "p2.Patron"."courtesy_notice", "p2.Patron"."delivery_privilege", "p2.Patron"."expiration_date", "p2.Patron"."general_block", "p2.Patron"."general_block_nt", "p2.Patr
on"."obj_id", "p2.Patron"."inv_barcode_num", "p2.Patron"."inv_barcode_num_eff_date", "p2.Patron"."barcode", "p2.Patron"."paging_privilege", "p2.Patron"."ole_stat_cat", "p2.Patron"."borr_typ", "p2.Patron"
."photograph", "p2.Patron"."ole_src", "p2.Patron"."ver_nbr"
FROM "krim_entity_t" AS "p2"
LEFT JOIN "krim_entity_priv_pref_t" AS "p2.PersonPrivacy" ON "p2"."entity_id" = "p2.PersonPrivacy"."entity_id"
LEFT JOIN "uc_entity_ext" AS "p2.PersonExt" ON "p2"."entity_id" = "p2.PersonExt"."id"
LEFT JOIN "ole_ptrn_t" AS "p2.Patron" ON "p2"."entity_id" = "p2.Patron"."ole_ptrn_id"
WHERE ("p2"."entity_id" = @__id_0) AND ("p2"."actv_ind" = Y)
LIMIT 2
ThreadId=11
DateTime=2018-02-28T01:08:11.5256865Z
OleWebApplication Critical: 0 : System.Web.HttpUnhandledException (0x80004005): Exception of type 'System.Web.HttpUnhandledException' was thrown. ---> Npgsql.PostgresException (0x80004005): 42703: column
"y" does not exist
at Npgsql.NpgsqlConnector.<DoReadMessage>d__157.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnector.<ReadMessage>d__156.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at Npgsql.NpgsqlConnector.<ReadMessage>d__156.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlConnector.<ReadExpecting>d__163`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlDataReader.<NextResult>d__32.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Npgsql.NpgsqlDataReader.NextResult()
at Npgsql.NpgsqlCommand.<Execute>d__71.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlCommand.<ExecuteDbDataReader>d__92.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
at Npgsql.NpgsqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.Execute(IRelationalConnection connection, DbCommandMethod executeMethod, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.ExecuteReader(IRelationalConnection connection, IReadOnlyDictionary`2 parameterValues)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
at Microsoft.EntityFrameworkCore.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
at System.Linq.Enumerable.WhereSelectEnumerableIterator`2.MoveNext()
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ResultEnumerable`1.GetEnumerator()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
at System.Linq.Enumerable.First[TSource](IEnumerable`1 source)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass15_1`1.<CompileQueryCore>b__0(QueryContext qc)
at OleWebApplication.People.Edit.PersonFormView_DataBinding(Object sender, EventArgs e) in C:\Users\jemiller\Documents\Visual Studio 2017\Projects\Ole5\OleWebApplication\People\Edit.aspx.cs:line 31
The query being run is.
var p = oleContext.People.Include(p2 => p2.Patron).Include(p2 => p2.PersonExt).Include(p2 => p2.PersonPrivacy).SingleOrDefault(p2 => p2.Id == id && p2.Active == "Y");
@jemiller0
I wonder if Oracle's MySQL provider works? I switched to Pomelo awhile back because Oracle was taking a long time getting their provider to work. Maybe it is better now.
Oracle's 2.0 provider does this, using the same code in the OP:
System.MissingMethodException: 'Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory..ctor(Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger`1<Command>, Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)'.'
A more complex model will throw this:
System.NotImplementedException: 'The 'MySQLNumberTypeMapping' does not support value conversions. Support for value conversions typically requires changes in the database provider.'
Stack traces omitted for brevity
That thoroughly sounds like Oracle's problem, not EF, so I don't know if the EF team wants a new issue opened for Oracle's provider or not, given their statement regarding 2.0 providers should work on 2.1 EF. @ajcvickers will you provide guidance?
@jemiller0 ok thanks - yeah, that's a known issue.
(and thanks for the kind words!)
@AdamDotNet Yes, please file an issue with Oracle. Providers really need to avoid using internal code because they need to keep working after EF Core updates.
Oracle bug report: https://bugs.mysql.com/bug.php?id=89855
@ajcvickers I haven't looked at the code, but, could you make it so that the internal packages are use the C# internal or private keywords to prevent people from using them? I'm assuming there is probably a reason you haven't already done this. If not, maybe you can make them inaccessible to prevent providers from doing this in the future.
@jemiller0 I wrote a blog post on it a while ago: https://blog.oneunicorn.com/2016/11/09/internal-code-in-ef-core-1-1/
In general I think that having internal code available to use is working well for application-level development. The problem is provider writers need to be more diligent and understand the consequences. I'm hoping that we can work through this and we are not forced to take away access to internal code, but certainly if it causes enough problems, then that's what we will have to do.
@ajcvickers Please dont!! - but provide clear provider guidance/advise
@ErikEJ We do need to be better about communicating changes to provider writers. I chatted with Shay about this when he was here--it would be good to hear your thoughts. Are you at the summit next week?
Yes, I am 😎
Hi everyone I'm using EntityFrameworkCore 2.1.0-preview2-final with Pomelo.EntityFrameworkCore.MySql 2.0.1 and I'm getting the same issue with 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalParameterBuilder..ctor(Microsoft.EntityFrameworkCore.Storage.IRelationalTypeMapper)'. Is there any way to solve it?
Thanks in advance.
@gsaldana The Pomelo MySQL provider is currently not working with EF Core 2.1. We are looking into potential ways that we can help with this, but we don't have concrete plans yet.
Is there an open ticket we can track to stay current on this?
Thanks
@sam-wheat - PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#497
Well this is concerning.