Skip to content

Instantly share code, notes, and snippets.

@istupakov
Created February 13, 2016 23:55
Show Gist options
  • Save istupakov/6086792de78f68eb1784 to your computer and use it in GitHub Desktop.
Save istupakov/6086792de78f68eb1784 to your computer and use it in GitHub Desktop.
Bug in .NET Core. Method not found: Expression.Update
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"
}
}
}
@istupakov
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment