Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

567
Views
Expressions static method requires null instance non-static method requires non-null instance

I'm new to using Expressions and am getting the following error:

System.ArgumentException : Static method requires null instance, non-static method requires non-null instance.
Parameter name: method

The code is as follows:

        int inP = 100;
        object inParam = inP;
        Type inParamType = inParam.GetType();

        ParameterExpression pe = Expression.Parameter(typeof(S), "pe");

        Expression left = Expression.Property(pe, typeof(S).GetProperty(propName));
        Expression right = Expression.Constant(inParam, inParamType);

        MethodInfo mi = inParamType.GetMethod(operand, BindingFlags.Instance | BindingFlags.Public, null, new Type[] { typeof(object) }, null);
        Expression e1 = Expression.Call(mi, left, right);
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You're using BindingFlags.Instance, so you'll only get back instance methods. Instance methods must be called as C# a.f(b), not f(a, b), and that translates to expression tree Expression.Call(left, mi, right), not Expression.Call(mi, left, right). That's what the exception is telling you:

Static method requires null instance, non-static method requires non-null instance.

In this case you have a non-static method, therefore you must pass in an instance on which to call the method.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!