You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
InvalidProgramException with System.Linq.Expressions and user-defined conditional operators #103197
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 a TryCatch expression on the right hand side of the conditional logic operator (AndAlso or OrElse). If I reorder the arguments so the TryCatch expression is on the left hand side of the operator it works as expected.
I am not sure why and how it used to work in .NET Framework.
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.
Activity
dotnet-policy-service commentedon Jun 8, 2024
Tagging subscribers to this area: @cston
See info in area-owners.md if you want to be subscribed.
EgorBo commentedon Jun 11, 2024
I presume in C# it would look like
condition || try { .... Checked JIT reports your snippet as an invalid program due to:My understanding that it is an expected behavior according to ECMA-335
I.12.4.2.8.1 Fall Through: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
jkotas commentedon Jun 11, 2024
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.
jkotas commentedon Jun 11, 2024
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.
jkotas commentedon Jun 26, 2024
cc @VSadov
Expression.Compile: empty the evaluation stack before evaluating seco…
Expression.Compile: empty the evaluation stack before evaluating seco…