Expression cannot contain lambda expressions

50,645

Solution 1

Evaluating Lambda expressions in debugger (watch window) is not supported yet.

Theres an open feature request for it.

For debugging your problem you should assign the result of the lambda expression to a dedicated variable and use that in following statements.

var entity = entityvDetails.Where(e => e.sad_id == item.sad_id).FirstOrDefault();

Update 08/2014: Microsoft posted an update on the feature request announcing that they started to work on it:

So here’s where we stand.

  • 1) We want this to work as much as you do. It’s not under review – it’s in progress.
  • 2) We figured out how to make it work; it simply requires rewriting everything.
  • 3) We’re rewriting everything.
  • 4) Rewriting everything takes a lot of time and a lot of testing.

Update 11/2014: Microsoft finally implemented it with some limitations in VS2015. Read here.

Solution 2

If you still need to use Visual Studio 2010 or 2013, you can use lambda expressions in the package manager console. For details, please see my SO post here:

Why is it not possible to evaluate lambdas in the immediate window?

This is the original source

Share:
50,645
Khadim Ali
Author by

Khadim Ali

DYNAMICS 365 (CRM) / POWER APPS TECHNICAL CONSULTANT Having 15+ years of experience in IT industry, my skill set includes following: • Microsoft Power Apps • Microsoft Power Platform Build Tools for Azure DevOps (Build/Release Pipelines) • Microsoft Azure DevOps (Repos, Azure Boards) • Microsoft Power Automate/Flows • Dynamics 365 (CRM) Online & On-premises (2013-2020 Release Wave 2) • Microsoft Dynamics 365 Marketing • LinkedIn Sales Navigator (Integration, Admin) • Power Apps Portals/CRM Portals • Dynamics 365 Customer Voice • Omnichannel for Dynamics 365 Customer Service • SQL Server Integration Services (SSIS) • Scribe/KingswaySoft integration tools • Microsoft Azure Service Bus (Relays) • Microsoft Azure Blob Storage • Microsoft Azure Functions • Visual Studio (2015-2019) • C#, .NET Framework • ASP.NET, ASP.NET MVC • Windows Communication Foundation (WCF) • Entity Framework, LINQ • Microsoft Bot Framework • SignalR client • Crystal Reports, SQL Server Reporting Services (SSRS) • MS SQL Server, Azure SQL Database, MySQL • JavaScript, jQuery, Ajax, JSON, OData/REST

Updated on February 07, 2020

Comments

  • Khadim Ali
    Khadim Ali about 4 years

    I have fetched the List<> object as below (with .Include()):

    List<vDetail> entityvDetails =
        context.vDetails
        .Include("payInstallment.appsDetail")
        .Include("payInstallment.appsDetail.application")
        .Include("payInstallment.appsDetail.purposes")
        .Where(e => e.vch_id == 123).ToList();
    

    And then somewhere in the code ahead I tried to filter the entity record as below:

    foreach (vDetail item in lstVDetails)
    {
        ... 
    
        int purposeId = entityvDetails.Where(e => e.sad_id == item.sad_id).FirstOrDefault().payInstallment.appsDetail.purposes.prp_id;
    
        ...
    }
    

    Code compiling perfect. However, the runtime returning following error (although all navigations are included):

    Object reference not set to an instance of an object.
    

    So I set for debugging using the watch window. Now while analyzing the below statement in watch window:

    entityVoucherDetails.Where(e => e.sad_id == item.sad_id).FirstOrDefault()
    

    the watch window generated following error:

    Expression cannot contain lambda expressions.

    Please if anybody can tell me what could be the reason?

  • TugboatCaptain
    TugboatCaptain over 9 years
    Microsoft, where IDE tools to deal with existing language features are considered extras.
  • Khadim Ali
    Khadim Ali over 9 years
    Support for debugging lambda expressions is now included in Visual Studio 2015. Cheers. blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/…
  • Alex McMillan
    Alex McMillan about 7 years
    @KhadimAli I have Visual Studio 2015 and now, in 2017, I am still seeing this message. Is there some kind of non-automatic-update, or settings flag I need to toggle?
  • Khadim Ali
    Khadim Ali about 7 years
    I am not sure about it as I haven't used this in VS2015 yet. BTW, did you try the exact same simple example found over the blog link above? If that executes then try isolating the issue by gradually making the example complex to be close to your expression. Finally you may post your code on another thread providing more details and findings.
  • stomy
    stomy about 6 years
    In Visual Studio 2012 when running PM> $dte.Debugger.GetExpression("orders.Where(o => o.IsValid == true)"); still getting "Value: Expression cannot contain lambda expressions". Only way was to run for loop PM> for($i = 0; $i -lt $dte.Debugger.GetExpression("orders.Count()").Value; $i++) { $a = $dte.Debugger.GetExpression("orders[$i]"); if ($a.Value.IsValid -eq $true) { Write-Host $i ") " $a.Value $a.Value.IsValid } }.
  • Shimmy Weitzhandler
    Shimmy Weitzhandler about 6 years
    Issue still on VS 2017!
  • Graham Laight
    Graham Laight about 2 years
    Issue still exists in VS 2019.