37

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?

1
  • 1
    FirstOrDefault explicitely allows nullrefs. If you are sure its never null use First. Do more checks for nullref over multiple lines before assuming something is not null. Will also help with debugging this. Assign the result of entityvDetails.Where(e => e.sad_id == item.sad_id).FirstOrDefault() to a dedicated variable. Commented May 5, 2014 at 10:50

2 Answers 2

61

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.

Sign up to request clarification or add additional context in comments.

6 Comments

Microsoft, where IDE tools to deal with existing language features are considered extras.
Support for debugging lambda expressions is now included in Visual Studio 2015. Cheers. blogs.msdn.com/b/visualstudioalm/archive/2014/11/12/…
@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?
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.
Issue still on VS 2017!
|
3

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

1 Comment

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 } }.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.