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

  • Home
  • SEARCH
  • 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 7818111
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T06:28:03+00:00 2026-06-02T06:28:03+00:00

Using AutoMapper, I hit a place where a named argument would’ve fit very nicely:

  • 0

Using AutoMapper, I hit a place where a named argument would’ve fit very nicely:

.ForMember(s => s.MyProperty, opt => opt.MapFrom(s => BuildMyProperty(s, isAdvanced: false)))

But the compiler yelled at me:

An expression tree may not contain a named argument specification

So I had to revert to:

.ForMember(s => s.MyProperty, opt => opt.MapFrom(s => BuildMyProperty(s, false)))

Does anyone know why the compiler disallows named arguments in this situation?

  • 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-02T06:28:05+00:00Added an answer on June 2, 2026 at 6:28 am

    Consider the following:

    static int M() { Console.Write("M"); return 1; }
    static int N() { Console.Write("N"); return 2; }
    static int Q(int m, int n) { return m + n; }
    ...
    Func<int> f = ()=>Q(n : N(), m: M());
    Expression<Func<int>> x = ()=>Q(n : N(), m: M());
    Func<int> fx = x.Compile();
    Console.WriteLine(f());
    Console.WriteLine(fx());
    

    You agree I hope that the last two lines must do exactly the same thing, right? Which is to print NM3.

    Now, what expression tree library calls would you like the expression tree conversion to generate that ensure this? There are none! We are therefore faced with the following choices:

    1. Implement the feature in the expression tree library. Add a transformation in the expression tree lowering engine that preserves the order of execution of the named arguments. Implement code in the Compile method that takes the execution order into account.
    2. Make x = ()=>Q(n : N(), m: M()); actually be implemented as x = ()=>Q(M(), N()); and be incompatible with the non-expression-tree version.
    3. Disallow named arguments in expression trees. Implement an error message to that effect.

    (1) is nice, but expensive. (2) is a non-starter; we can’t in good conscience introduce this kind of “gotcha”. (3) is cheap but irritating.

    We chose (3).

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

Sidebar

Related Questions

I am using AutoMapper where it has: .ForMember( dest => dest.id, opt => opt.MapFrom(src
Any idea how I can tell AutoMapper to resolve a TypeConverter constructor argument using
I am using AUtomapper which I am very impressed with however, I have a
I've been using AutoMapper successfully for a while now. However, when I use MapFrom()
I am using AutoMapper.org to map my DTO objects to Model objects in MVC4.
I am using AutoMapper to datareader using code as discussed below http://elegantcode.com/2009/10/16/mapping-from-idatareaderidatarecord-with-automapper/ I see
Using Jenkins or Hudson I would like to create a pipeline of builds with
I am using automapper (successfully up to a point) to perform a polymorphic map
I've been using AutoMapper for a few months now with success but now I've
I am using AutoMapper in my project along with, NHibernate and ASP.NET MVC 2.

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.