Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7998829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:19:40+00:00 2026-06-04T15:19:40+00:00

I am having some trouble with compiling a lambda expression for a property getter

  • 0

I am having some trouble with compiling a lambda expression for a property getter in F# if the delegate type is internal. This is what the function looks like:

// if I omit the 'internal' here everything works as expected
module internal ReflectionHelpers =

    open System
    open System.Linq.Expressions
    open System.Reflection

    // it makes no difference if this delegate type is defined outside
    // of the module and marked as 'internal'
    type GetterFunc<'T> = delegate of 'T -> obj

    /// Build a getter expression function for the
    /// specified PropertyInfo
    let getGetter<'a> (p : PropertyInfo) =
        let inst = Expression.Parameter(p.DeclaringType, "i")
        let prop = Expression.Property(inst, p)
        let conv = Expression.Convert(prop, typeof<obj>)
        Expression.Lambda<GetterFunc<'a>>(conv, inst).Compile()

If I call this method with a public class I get an exception like this one (only if the ReflectionHelpers module is defined as ‘internal’):

System.ArgumentNullException was unhandled by user code
  Message=Value cannot be null.
Parameter name: key
  Source=mscorlib
  ParamName=key
  StackTrace:
       at System.Collections.Generic.Dictionary`2.FindEntry(TKey key)
       at System.Collections.Generic.Dictionary`2.TryGetValue(TKey key, TValue& value)
       at System.Dynamic.Utils.CacheDict`2.TryGetValue(TKey key, TValue& value)
       at System.Dynamic.Utils.TypeExtensions.GetParametersCached(MethodBase method)
       at System.Linq.Expressions.Expression.ValidateLambdaArgs(Type delegateType, Expression& body, ReadOnlyCollection`1 parameters)
       at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, String name, Boolean tailCall, IEnumerable`1 parameters)
       at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, Boolean tailCall, IEnumerable`1 parameters)
       at System.Linq.Expressions.Expression.Lambda[TDelegate](Expression body, ParameterExpression[] parameters)
       ...

Probably I am missing an important point here but currently I cannot see any reason why this is happening.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T15:19:41+00:00Added an answer on June 4, 2026 at 3:19 pm

    F# and C# use different strategies for emitting Invoke method for delegates. If you try to define similar delegate in C# it – delegate type will be internal but with public Invoke method. F# defines Invoke method with the same visibility as the declaring type. When code in Expression.Lambda tries to find Invoke method in given delegate type it looks only for public methods assuming that all compilers behave similar to C#

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having some trouble writing a getstring function, this is what I have so
I'm having trouble compiling some C code. When I compile, I'l get this error:
Im having some trouble with joining two tables. This is what my two tables
I'm having some trouble compiling/linking a set of classes, several of them dealing with
I'm having trouble compiling some code against ocilib (libocilib.a) on version 3.9.0: $ ls
Hopefully this should be a quick question. I'm having trouble accessing some movie clips
I'm having some trouble understanding why this code won't work. I got it from
I'm having some trouble compiling my code - it has to do with the
I'm having some trouble compiling my work, I'm using Ubuntu with g++ . I
having some trouble with this can't understand why it won't work properly. http://host.philmadelphia2.com/~clare/order/ when

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.