Created
February 13, 2016 23:55
-
-
Save istupakov/6086792de78f68eb1784 to your computer and use it in GitHub Desktop.
Bug in .NET Core. Method not found: Expression.Update
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq.Expressions; | |
namespace ConsoleApp | |
{ | |
class Visitor : ExpressionVisitor | |
{ | |
protected override Expression VisitParameter(ParameterExpression node) | |
{ | |
return Expression.Constant(1.0); | |
} | |
protected override Expression VisitLambda<T>(Expression<T> node) | |
{ | |
return node.Update(Visit(node.Body), node.Parameters); | |
} | |
} | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
Expression<Func<double, double>> expr = t => 2 * t * t; | |
var f = expr.Compile(); | |
Console.WriteLine($"f(3) = {f(3)}"); // Write "f(3) = 18" | |
var visit = new Visitor(); | |
var newExpr = visit.VisitAndConvert(expr, "test"); // Exception thrown: 'System.MissingMethodException' in System.Linq.Expressions.dll | |
var g = newExpr.Compile(); | |
Console.WriteLine($"g(3) = {g(3)}"); // Must write "g(3) = 2" | |
} | |
} | |
} |
Author
istupakov
commented
Feb 13, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment