zzzprojects / EntityFramework-Classic

Entity Framework Classic is a supported version of the latest EF6 codebase. It supports .NET Framework and .NET Core and overcomes some EF limitations by adding tons of must-haves built-in features.
https://entityframework-classic.net
Other
102 stars 27 forks source link

Exception: NullReferenceException when using .Where(x => x.Field.Contains(txt)) #20

Closed luca-esse closed 5 years ago

luca-esse commented 5 years ago

The following query throws a NullReferenceException: Context.Games.Where(x => x.Name.Contains(searchText)).ToListAsync();

The problems seems to be the string.Contains() method.

EntityFramework-Classic version: 7.0.24

Here is the stack trace:

System.NullReferenceException: Object reference not set to an instance of an object. at System.Linq.Expressions.Compiler.LambdaCompiler.EmitMethodCall(Expression obj, MethodInfo method, IArgumentProvider methodCallExpr, CompilationFlags flags) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitInvocationExpression(Expression expr, CompilationFlags flags) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitInstance(Expression instance, Type& type) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitMemberExpression(Expression expr) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitExpression(Expression node, CompilationFlags flags) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody(CompilerScope parent, Boolean inlined, CompilationFlags flags) at System.Linq.Expressions.Compiler.LambdaCompiler.EmitLambdaBody() at System.Linq.Expressions.Compiler.LambdaCompiler.Compile(LambdaExpression lambda) at System.Data.Entity.Core.Objects.ELinq.QueryParameterExpression.EvaluateParameter(Object[] arguments) at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable1 forMergeOption) at System.Data.Entity.Core.Objects.ObjectQuery1.<>c__DisplayClass43_0.b__1() at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransactionAsync[T](Func1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess, CancellationToken cancellationToken) at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.ExecuteAsyncImplementation[TResult](Func1 func) at System.Data.Entity.Core.Objects.ObjectQuery1.GetResultsAsync(Nullable1 forMergeOption, IDbExecutionStrategy executionStrategy, CancellationToken cancellationToken) at System.Data.Entity.Internal.LazyAsyncEnumerator1.FirstMoveNextAsync(CancellationToken cancellationToken) at System.Data.Entity.Infrastructure.IDbAsyncEnumerableExtensions.SingleAsync[TSource](IDbAsyncEnumerable1 source, CancellationToken cancellationToken)

JonathanMagnan commented 5 years ago

Hello @luca-esse ,

We successfully reproduced that issue on NET Core, but it works perfectly on NET Framework.

That kind of issue normally happens when a method is no longer available in .NET Code.

It happens when the method tries to compile the current expression ( QueryParameterExpression (line: 65))

We will investigate it on Monday.

Best Regards,

Jonathan

luca-esse commented 5 years ago

Hi Jonathan, Do you have any update?

Best regards, Luca

JonathanMagnan commented 5 years ago

Hello @luca-esse ,

We passed a lot of time this week on this issue.

We can easily reproduce it, easily find out which line fail.

However, it's currently very hard to find out what's causing it as that happen when a compiled expression is executed.

We continue to investigate it but that one is currently harder to find that we initially though.

JonathanMagnan commented 5 years ago

Hello @luca-esse ,

Sorry for being so long, that one is not easy ;(

We finally made a good discovery today about the Expression used that cause the issue.

The expression work on .NET Framework but not on NET Core

JonathanMagnan commented 5 years ago

Hello @luca-esse ,

The v7.0.29 has been released.

Let me know if everything works as expected.

Best Regards,

Jonathan

luca-esse commented 5 years ago

Hello @JonathanMagnan

Can confirm it's working with the v7.0.29 :)

Best regards, Luca

JonathanMagnan commented 5 years ago

Great ;)