Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SqliteMathTranslator throws an exception on ubuntu in .Net 6 / EFCore 6 preview 6 #25314

Closed
Webreaper opened this issue Jul 22, 2021 · 8 comments

Comments

@Webreaper
Copy link

Webreaper commented Jul 22, 2021

I upgraded my project to use .Net 6 preview-6, and EFCore 6 preview-6. It worked fine on MacOS. However, when I built and deployed the project to Linux/Ubuntu via docker, it crashed with:

ThreadPool Worker-ERR] Exception caught during metadata scan: System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteMathTranslator' threw an exception.
 ---> System.InvalidOperationException: Operation is not valid due to the current state of the object.
   at System.SharedTypeExtensions.GetRequiredMethod(Type type, String name, Type[] parameters) in Microsoft.EntityFrameworkCore.Sqlite.dll:token 0x6000011+0x31
   at Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteMathTranslator..cctor() in Microsoft.EntityFrameworkCore.Sqlite.dll:token 0x6000199+0x6f3
   --- End of inner exception stack trace ---
   at Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteMathTranslator.Translate(SqlExpression instance, MethodInfo method, IReadOnlyList`1 arguments, IDiagnosticsLogger`1 logger) in Microsoft.EntityFrameworkCore.Sqlite.dll:token 0x6000198+0x25
   at Microsoft.EntityFrameworkCore.Query.RelationalMethodCallTranslatorProvider.<>c__DisplayClass4_0.<Translate>b__0(IMethodCallTranslator t) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x6001973+0x0
   at System.Linq.Enumerable.SelectEnumerableIterator`2.MoveNext() in System.Linq.dll:token 0x60001c1+0x36
   at System.Linq.Enumerable.TryGetFirst[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found) in System.Linq.dll:token 0x6000085+0x34
   at System.Linq.Enumerable.FirstOrDefault[TSource](IEnumerable`1 source, Func`2 predicate) in System.Linq.dll:token 0x6000082+0x0
   at Microsoft.EntityFrameworkCore.Query.RelationalMethodCallTranslatorProvider.Translate(IModel model, SqlExpression instance, MethodInfo method, IReadOnlyList`1 arguments, IDiagnosticsLogger`1 logger) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60007e8+0x181
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008da+0x889
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.TryRewriteEntityEquality(ExpressionType nodeType, Expression left, Expression right, Boolean equalsMethod, Expression& result) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008e7+0x270
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008d1+0xd3
   at Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression) in Microsoft.EntityFrameworkCore.Sqlite.dll:token 0x60001bb+0xc
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008d1+0xad
   at Microsoft.EntityFrameworkCore.Sqlite.Query.Internal.SqliteSqlTranslatingExpressionVisitor.VisitBinary(BinaryExpression binaryExpression) in Microsoft.EntityFrameworkCore.Sqlite.dll:token 0x60001bb+0xc
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.TranslateInternal(Expression expression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008ca+0x0
   at Microsoft.EntityFrameworkCore.Query.RelationalSqlTranslatingExpressionVisitor.Translate(Expression expression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x60008c9+0x13
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateExpression(Expression expression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x6000841+0x0
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateLambdaExpression(ShapedQueryExpression shapedQueryExpression, LambdaExpression lambdaExpression) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x6000842+0x0
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.TranslateWhere(ShapedQueryExpression source, LambdaExpression predicate) in Microsoft.EntityFrameworkCore.Relational.dll:token 0x6000840+0x18
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x1347
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x5e
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x5e
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x5e
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x5e
   at Microsoft.EntityFrameworkCore.Query.QueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression) in Microsoft.EntityFrameworkCore.dll:token 0x60006a8+0x5e
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query) in Microsoft.EntityFrameworkCore.dll:token 0x60006f4+0x32
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async) in Microsoft.EntityFrameworkCore.dll:token 0x60003f2+0x0
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async) in Microsoft.EntityFrameworkCore.dll:token 0x6000873+0x0
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass9_0`1.<Execute>b__0() in Microsoft.EntityFrameworkCore.dll:token 0x6002938+0x0
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler) in Microsoft.EntityFrameworkCore.dll:token 0x60007e4+0x79
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.Execute[TResult](Expression query) in Microsoft.EntityFrameworkCore.dll:token 0x6000872+0x70
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.Execute[TResult](Expression expression) in Microsoft.EntityFrameworkCore.dll:token 0x6000806+0x0
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetEnumerator() in Microsoft.EntityFrameworkCore.dll:token 0x60007fc+0x0
   at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.IncludableQueryable`2.GetEnumerator() in Microsoft.EntityFrameworkCore.dll:token 0x60025ca+0x0
   at System.Collections.Generic.LargeArrayBuilder`1.AddRange(IEnumerable`1 ) in System.Linq.dll:token 0x6000014+0x0
   at System.Collections.Generic.EnumerableHelpers.ToArray[T](IEnumerable`1 ) in System.Linq.dll:token 0x6000029+0x3b
   at Damselfly.Core.Services.IndexingService.RunMetaDataScans() in Damselfly.Core.dll:token 0x6000086+0x0

My project a Blazor server app, and is using the Sqlite Provider. During the upgrade I'd added a new DateOnly field to my model.

Reverting to 6.0.0-preview.5.21301.9 and converting the DateOnly field to a DateTime field resolved the issue.

This is the revert commit that fixed the problem: Webreaper/Damselfly@5d17766

Possible Cause: DateOnly field in DBContext

I have not tested to see whether it works with EFCore 6-preview-6 without DateOnly yet. I will attempt that later this week, which should indicate if this is specifically related to preview-6 itself, or to DateOnly fields. I'll update the issue when I get a chance to try it.

EDIT: I was able to try the build with EFCore 6 preview-6, but without DateOnly being used, and the SqliteMatchTranslator exception still occurs. So it looks like this is a preview-6 issue, and DateOnly is a red-herring.

Include provider and version information

EF Core version: 6.0.0-preview.6.21352.1
Database provider: Microsoft.EntityFrameworkCore.Sqlite
Target framework: .Net 6.0 preview-6
Operating system: Synology Linux (an Ubuntu derivative) - in docker.
IDE: Visual Studio for Mac 8.10.6 (build 10)

@Webreaper Webreaper changed the title SqliteMathTranslator throws an exception on ubuntu in .Net 6 / EFCore 6 preview 6 with DateOnly field SqliteMathTranslator throws an exception on ubuntu in .Net 6 / EFCore 6 preview 6 Jul 22, 2021
@AndriySvyryd
Copy link
Member

Might be related to #25182

@Webreaper Webreaper reopened this Jul 28, 2021
@Webreaper
Copy link
Author

Apologies for the close/reopen, thought this was resolved, but it still happens.

@Webreaper
Copy link
Author

Webreaper commented Jul 30, 2021

Just to add to the issue, this is causing real problems. Here's where I am now:

  1. Installed preview 4, developed code on my Mac
  2. Installed preview 6, developed more code, including adding a new migration
  3. Deployed to Linux, found out preview 6 crashes there. Rolled back to preview 4
  4. Continue developing more code.
  5. Add new field, so decide to add a new migration. dotnet ef migrations add now crashes with:
Method 'Identifier' in type 'Microsoft.EntityFrameworkCore.Design.Internal.CSharpHelper' from assembly 'Microsoft.EntityFrameworkCore.Design, Version=6.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.

So now I'm in a position where the only way I can add new migrations is to upgrade my project to EF6 preview 6, add the migration, then downgrade to EF6 preview 4, so I can deploy to linux. 😭

@ErikEJ
Copy link
Contributor

ErikEJ commented Jul 30, 2021

@Webreaper Or stay on EF Core 5?

@Webreaper
Copy link
Author

Webreaper commented Jul 30, 2021

A few problems with that:

  1. It's no fun. ;)
  2. If everyone stayed on EFCore 5, how would the EFCore team ever tease out and fix bugs like this in the preview?
  3. I'd have to go back and remove all my migrations, and then re-add them after downgrading.
  4. I want the performance improvements in EFCore 6

But mainly #1. :)

@ajcvickers ajcvickers added this to the 6.0.0 milestone Jul 30, 2021
@ajcvickers
Copy link
Contributor

Marking as a bug in 6.0 so we can investigate.

@roji
Copy link
Member

roji commented Sep 7, 2021

@Webreaper I noticed that your repo is now on 6.0.0-preview.7, does that mean the issue above no longer happens? If it does, can you provide some quick instructions on reproing this with your project?

@roji roji assigned roji and unassigned bricelam Sep 7, 2021
@roji roji removed the poachable label Sep 7, 2021
@Webreaper
Copy link
Author

Webreaper commented Sep 7, 2021

Hi @roji - no, it's not happening any more. I'm not sure why it stopped happening. I think it might have possibly been because I had a hooky combination of dependencies (I'd had a hodge-podge of different versions to work around various issues). It caused all sorts of issues, and broke migrations for me. I realigned everything on preview 7 and the latest EF core, and I think it's all good now, so it may have just been some form of dependency mash-up/DLL-hell sort of thing.

You can probably close now, as I can't repro it any more (sorry, should have closed it myself when it went away - but forgot). If it crops up for anyone else they can always re-open if they find this issue.

PS: I haven't forgotten about creating a repro project for that table-join issue we were discussing; will try and get to that this week! :)

@roji roji closed this as completed Sep 7, 2021
@roji roji removed this from the 6.0.0 milestone Sep 7, 2021
@ajcvickers ajcvickers reopened this Oct 16, 2022
@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants