dbelmont / ExpressionBuilder

A library that provides a simple way to create lambda expressions to filter lists and database queries.
Apache License 2.0
372 stars 105 forks source link

System.TypeInitializationException #35

Open snill93 opened 6 years ago

snill93 commented 6 years ago

I'm trying to utilize the library in an ASP.NET Core 2.1 (preview) application but continue to get exceptions when running the following within a method in my data access layer / repository:

 var filter = new Filter<Persona>();
 filter.By("LastName", Operation.Contains, "Alex");  // exception here

And when I run this line (from above):

ASP.NET Core crashes with the following:

"exceptionType": "System.TypeInitializationException",
"stackTrace": " in ExpressionBuilder.Helpers.OperationHelper..ctor()\r\n in ExpressionBuilder.Operations.Operation..cctor()",

Could you give me some help? Thanks in advice!

Hobbes1987 commented 6 years ago

I got the same issue

dbelmont commented 6 years ago

Hi @snill93, @Hobbes1987, Sorry for the late reply. The project currently doesn't support .Net Core, but I'll be working on that. I'll try to keep you guys posted. Cheers.

dbelmont commented 5 years ago

Hi @snill93, @Hobbes1987,

I created a pre-release package at NuGet.org with support for .Net Core. Would you mind checking that out and leaving a comment here to let me know if it's working correctly now?

Many thanks, David

Arthur-Z commented 5 years ago

An unhandled exception occurred while processing the request.

AmbiguousMatchException: Ambiguous match found. System.RuntimeType.GetMethodImplCommon(string name, int genericParameterCount, BindingFlags bindingAttr, Binder binder, CallingConventions callConv, Type[] types, ParameterModifier[] modifiers)

TargetInvocationException: Exception has been thrown by the target of an invocation. System.RuntimeTypeHandle.CreateInstance(RuntimeType type, bool publicOnly, bool wrapExceptions, ref bool canBeCached, ref RuntimeMethodHandleInternal ctor)

TypeInitializationException: The type initializer for 'ExpressionBuilder.Helpers.OperationHelper' threw an exception. ExpressionBuilder.Helpers.OperationHelper..ctor()

TypeInitializationException: The type initializer for 'ExpressionBuilder.Operations.Operation' threw an exception. ExpressionBuilder.Operations.Operation.get_Contains()

filter.By(queryField.Field, ExpressionBuilder.Operations.Operation.Contains, queryField.Value);

EnricoWuestenberg commented 5 years ago

Get the same exception with EqlausTo. .net core 2.2 in asp core project.

soongsta commented 5 years ago

Same here for core 2.2 and equalsTo

GustavSt commented 5 years ago

@dbelmont no plans on improving support for .net core? I'm using the pre release and .net core 2.2

aldrashan commented 5 years ago

I've had the same issue. After debugging it seems the problem for me was a nuget package that didn't specify its dependencies. The nuget package that caused problems referenced another nuget package, but didn't actually use anything in that nuget package, causing our main project to not load in the "required" .dll or load in a different version of the .dll. The code used to fetch all types used in ExpressionBuilder (to initialize the operations) also searches for the types in the missing (or having an incorrect version) .dll, causing the exception.

Fixing the dependencies for that bad nuget package made ExpressionBuilder work again.

Either way, you should catch the System.Reflection.ReflectionTypeLoadException if you're having problems and look what library is giving troubles.

brentb25 commented 5 years ago

I'm getting the same error System.TypeInitializationException: The type initializer for 'ExpressionBuilder.Operations.Operation' threw an exception. ---> System.TypeInitializationException: The type initializer for 'ExpressionBuilder.Helpers.OperationHelper' threw an exception. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Reflection.AmbiguousMatchException: Ambiguous match found.

I'm using Xamarin Forms on IOS targeting .net standard 2.1 (tried 2.0 also to no avail)

Paul-ICS commented 4 years ago

It looks like this is already fixed in the repo. Could you push a new version to NuGet?

27