Support for EntityFramework 6
Describe the bug .Net Core 6 RC1 has just been released and has go-live support. When running workflow-core with 3.5.5 with WorkflowCore.Persistence.SqlServer, an exception is thrown:
System.TypeLoadException: Method 'AppendIdentityWhereCondition' in type 'Microsoft.EntityFrameworkCore.SqlServer.Update.Internal.SqlServerUpdateSqlGenerator' from assembly 'Microsoft.EntityFrameworkCore.SqlServer, Version=5.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' does not have an implementation.
To Reproduce Steps to reproduce the behavior:
- Run Workflow Core in a .Net 6 RC1 Project
Expected behavior Workflow core will need to be tweaked to support .Net 6
I was able to patch this issue by adding the net6.0 TFMs to the EF based packages and created a condition which uses the newest EF core packages. See the following commit, https://github.com/IvanJosipovic/workflow-core/commit/e6f82fbad14bc3d2d3f8d444f74df2b48aebce42
With the .Net 6 release coming up in November, we should think about how we're going to handle multiple framework versions.
- .Net 2.x - 3.0 are now End of Life and should be removed from the library
- There are a number of projects referencing TFM netcoreapp2.0 and netcoreapp3.0 and 2.x Packages and will need to be updated
- .Net 3.1 will continue to be supported
- .Net 5 is only supported 6 months after .Net 6 comes out
- .Net 6 will need to be supported
I think the simplest solution going foreword:
- All packages should have TFMs netcoreapp3.1;net5.0;net6.0 with associated conditions targeting that versions packages
See this doc for more details on the future TFMS, https://github.com/dotnet/designs/blob/main/accepted/2020/net5/net5.md
Do we know if work when the solution will support .Net 6? It looks like @IvanJosipovic has a good solution.
Hey, @danielgerlag, any thoughts on the above? I can help with the PR if you recommend the approach.
This is not a .net 6 issue, this is an EnityFramework 6 backward compatibility issue. For now, you can still use EF5 with .net 6. We will continue to target the .net standard 2 specification in the core libraries, which is implemented by all the frameworks supported. The EF libraries will not be backward compatible, we will retarget those only.
I actually just tested the current published EF libraries with a .net 6 app that uses EF6 and it worked without issue. The error you were seeing was due to prerelease EF libraries.
Hi @danielgerlag,
To give a few more details of the issue I'm having.
Environment: Target Framework:
net6.0
Workflow Core Version:

Database: I'm not using Entity Framework in my solution. Also, I've dropped and recreated my database locally to rule out data migration issues,
Exception: The below happened immediately upon starting in a clean environment.
WorkflowCore.Services.BackgroundTasks.RunnablePoller: Information: Polling for runnable workflows
WorkflowCore.Services.BackgroundTasks.RunnablePoller: Error: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
System.TypeInitializationException: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
---> System.InvalidOperationException: Sequence contains more than one matching element
at System.Linq.ThrowHelper.ThrowMoreThanOneMatchException()
at System.Linq.Enumerable.TryGetSingle[TSource](IEnumerable`1 source, Func`2 predicate, Boolean& found)
at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
at Microsoft.EntityFrameworkCore.Query.QueryableMethods..cctor()
--- End of inner exception stack trace ---
at Microsoft.EntityFrameworkCore.Query.Internal.QueryableMethodNormalizingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPreprocessor.NormalizeQueryableMethod(Expression expression)
at Microsoft.EntityFrameworkCore.Query.QueryTranslationPreprocessor.Process(Expression query)
at Microsoft.EntityFrameworkCore.Query.RelationalQueryTranslationPreprocessor.Process(Expression query)
at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryable`1.GetAsyncEnumerator(CancellationToken cancellationToken)
at Microsoft.EntityFrameworkCore.EntityFrameworkQueryableExtensions.ToListAsync[TSource](IQueryable`1 source, CancellationToken cancellationToken)
at WorkflowCore.Persistence.EntityFramework.Services.EntityFrameworkPersistenceProvider.GetRunnableInstances(DateTime asAt, CancellationToken cancellationToken)
at WorkflowCore.Services.BackgroundTasks.RunnablePoller.PollWorkflows()
at WorkflowCore.Services.BackgroundTasks.RunnablePoller.PollWorkflows()
WorkflowCore.Services.BackgroundTasks.RunnablePoller: Information: Polling for unprocessed events
WorkflowCore.Services.BackgroundTasks.RunnablePoller: Error: The type initializer for 'Microsoft.EntityFrameworkCore.Query.QueryableMethods' threw an exception.
Mitigation
To stop this error, I've downgraded the Target Framework for my solution to net5.0.
Let me know if you need more information or you would like me to test anything.
@Westmorland I am not able to reproduce this issue. FYI, you are using Entity Framework in your project by using the SQL Persistence package. What other packages did you upgrade/downgrade when switching .net versions?
@danielgerlag, I have a reproduced broken version you can look at here, https://github.com/IvanJosipovic/workflow_core_net6
I actually just tested the current published EF libraries with a .net 6 app that uses EF6 and it worked without issue. The error you were seeing was due to prerelease EF libraries.
This comment made me figure out the fix, your app referenced EF6 which made workflow-core use EF6. However, if your app doesn't use EF then it will default to EF5.
@Westmorland The workaround for now is to add the following to your csproj
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.0" />
@IvanJosipovic - Thank you very much, I can confirm the workaround suggested has worked for my solution.