-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InvalidProgramException with System.Linq.Expressions and user-defined conditional operators #103197
Comments
Tagging subscribers to this area: @cston |
I presume in C# it would look like
My understanding that it is an expected behavior according to ECMA-335
so I am not sure why and how it used to work in .NET Framework.
if it's on the left side then the evaluation stack is empty cc @jkotas |
The IL produced by the expression compiler on .NET Framework has an extra spill to make the stack empty. It looks like a regression in System.Linq.Expressions to me. |
Note that we merged a ton of optimizations in S.L.Expressions in the early .NET Core days: https://github.com/dotnet/corefx/pulls?q=label%3Aarea-System.Linq.Expressions+is%3Aclosed+optimize . It is likely one of those of changes. |
Description
Using
System.Linq.Expressions
to build expression trees dynamically, the repro code worked as expected in .NET Framework but fails in .NET (tested .NET 6 & .NET 8)So far I've managed to narrow this down to when I'm using a type that implements custom conditional operators (
true
,false
,&
and|
) and using aTryCatch
expression on the right hand side of the conditional logic operator (AndAlso
orOrElse
). If I reorder the arguments so theTryCatch
expression is on the left hand side of the operator it works as expected.Reproduction Steps
Expected behavior
The expression should compile and
True
should be printed to the console.Actual behavior
A
System.InvalidProgramException
is thrown bylambda.Compile()
Regression?
Yes - this same code runs as expected in .NET Framework 4.6.2 and 4.8
Known Workarounds
No response
Configuration
.NET 6 and .NET 8
Windows 11 22631.3593
x64
Doesn't appear to be specific to this.
Other information
No response
The text was updated successfully, but these errors were encountered: