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

System.TypeInitializationException #35

Open
snill93 opened this issue Jul 27, 2018 · 10 comments
Open

System.TypeInitializationException #35

snill93 opened this issue Jul 27, 2018 · 10 comments

Comments

@snill93
Copy link
Contributor

snill93 commented Jul 27, 2018

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
Copy link

I got the same issue

@dbelmont
Copy link
Owner

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
Copy link
Owner

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
Copy link

Arthur-Z commented Mar 5, 2019

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
Copy link

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

@soongsta
Copy link

Same here for core 2.2 and equalsTo

@GustavSt
Copy link

GustavSt commented Jun 5, 2019

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

@aldrashan
Copy link

aldrashan commented Jun 26, 2019

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
Copy link

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
Copy link

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

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

10 participants