dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.06k stars 4.69k forks source link

Debugger display of compiled lambda shows "Internal Error evaluating expression" #33479

Open AaronHerchmer opened 4 years ago

AaronHerchmer commented 4 years ago

Hi,

I'm trying to compile a Func delegate from an expression for filtering a collection in .NET Core 3.1 and after calling .Compile() on the expression the value of the delegate is:

{Method = \<Internal Error evaluating expression>}

When I run the exact same code in a .NET 4.7.2 console application, it works, and I am able to filter a collection using that delegate.

var expressionParameter = Expression.Parameter(typeof(DateTime), "x");
var expressionProperty = Expression.Property(expressionParameter, "Date");

var expressionValue = Expression.Constant(new DateTime(2020, 03, 10), typeof(DateTime));
var compareExpression = Expression.GreaterThanOrEqual(expressionProperty, expressionValue);

var lambdaExpression = Expression.Lambda<Func<DateTime,bool>>(compareExpression, expressionParameter);
var testCompile = lambdaExpression.Compile();
GrabYourPitchforks commented 4 years ago

Can you clarify your issue? Is is that you're seeing a problem with the VS debugger specifically, or is the application failing at runtime?

AaronHerchmer commented 4 years ago

I'm just seeing the result in the VS debugger, the value of the variable testCompile is {Method = \<Internal Error evaluating expression>} in .NET Core, and an appropriate Func in 4.7.2.

stephentoub commented 4 years ago

But does testCompile still work? The question is if the concern is just around debugging or if it's actually affecting behavior at run-time.

AaronHerchmer commented 4 years ago

Ya sorry it still returns the delegate properly just the value of the display inside the debugger is incorrect. The delegate still works at runtime.

theCuriousOne commented 4 years ago

I am experiencing the same error. We have just upgraded our code from .net core 2.1 to 3.1 and while in 2.1 I see no such error in 3.1 it shows:

{Method = <Internal Error evaluating expression>}

I also have a failing test that I am trying to debug, and now I am not sure if something have changed in the Expressions between versions 2.1 and 3.1 or it is an debugger issue and I am looking in the wrong place.

sidney-pauly commented 4 years ago

I had a similar issue to @theCuriousOne. I detailed my solution/bug-report here: #35336

theCuriousOne commented 4 years ago

I had a similar issue to @theCuriousOne. I detailed my solution/bug-report here: https://github.com/dotnet/runtime/issues/35336

@sidney-pauly your url is incorrect https://github.com/dotnet/runtime/issues/35336 it should be placed in both brackets -> in [] is for text that you see, and in () is the link behind the text.

cston commented 4 years ago

{Method = \}

The delegate is a dynamic method which is not viewable in the debugger.

theCuriousOne commented 4 years ago

@cston The same code was viewable in VisualStudio 2017, but not in VisualStudio 2019. The question is: what change in the debugger caused this? Was the VS2017 version wrong or did it handled it better?

CzBuCHi commented 1 year ago

got same error but i managed to find workaround:

instead of having delegate in watch use delegate.Method - then debugger shows correct method info

info from visual studio help->about :

Microsoft Visual Studio Community 2022
Version 17.3.4
VisualStudio.17.Release/17.3.4+32901.215
Microsoft .NET Framework
Version 4.8.04084

Installed Version: Community

Visual C++ 2022   00482-90000-00000-AA207
Microsoft Visual C++ 2022

ADL Tools Service Provider   1.0
This package contains services used by Data Lake tools

ASA Service Provider   1.0

ASP.NET and Web Tools   17.3.376.3011
ASP.NET and Web Tools

Azure App Service Tools v3.0.0   17.3.376.3011
Azure App Service Tools v3.0.0

Azure Data Lake Tools for Visual Studio   2.6.5000.0
Microsoft Azure Data Lake Tools for Visual Studio

Azure Functions and Web Jobs Tools   17.3.376.3011
Azure Functions and Web Jobs Tools

Azure Stream Analytics Tools for Visual Studio   2.6.5000.0
Microsoft Azure Stream Analytics Tools for Visual Studio

C# Tools   4.3.0-3.22423.10+b35bb0baca1071d50cc4f8cf5a1a89e7cc112461
C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Common Azure Tools   1.10
Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.

Markdown Editor v2   2.0.130
A full featured Markdown editor with live preview and syntax highlighting. Supports GitHub flavored Markdown.

Microsoft Azure Hive Query Language Service   2.6.5000.0
Language service for Hive query

Microsoft Azure Stream Analytics Language Service   2.6.5000.0
Language service for Azure Stream Analytics

Microsoft JVM Debugger   1.0
Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines

NuGet Package Manager   6.3.0
NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/

Razor (ASP.NET Core)   17.0.0.2232702+e1d654e792aa2fe6646a6935bcca80ff0aff4387
Provides languages services for ASP.NET Core Razor.

SQL Server Data Tools   17.0.62207.04100
Microsoft SQL Server Data Tools

ToolWindowHostedEditor   1.0
Hosting json editor into a tool window

TypeScript Tools   17.0.10701.2001
TypeScript Tools for Microsoft Visual Studio

Visual Basic Tools   4.3.0-3.22423.10+b35bb0baca1071d50cc4f8cf5a1a89e7cc112461
Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used.

Visual F# Tools   17.1.0-beta.22363.4+1b94f89d4d1f41f20f9be73c76f4b229d4e49078
Microsoft Visual F# Tools

Visual Studio IntelliCode   2.2
AI-assisted development for Visual Studio.

PS: yea i know this post is 2 years old ...