[Mono-bugs] [Bug 475962] exception thrown from CreateDelegate () when compiling Expression returning a delegate

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Wed Mar 18 12:45:18 EDT 2009


User saiya.v6 at gmail.com added comment

Seiya Yazaki <saiya.v6 at gmail.com> changed:

           What    |Removed                     |Added
                 CC|                            |saiya.v6 at gmail.com

--- Comment #4 from Seiya Yazaki <saiya.v6 at gmail.com>  2009-03-18 10:45:18 MST ---
I have seen mono 2.2 source code about this issue and tried above codes.

Then I have found that second argument of
MethodCallExpression(Delegate.CreateDelegate) is null.

Second argument of Delegate.CreateDelegate(Type, Object, MethodInfo) is
expected to be not null because the d.testFunc isn't static method call form.

So I think there are bug during translation from C# source code into

Following is a code to see that the second argument for Delegate.CreateDelegate
is null (Based on Zoltan's code).

--- Sample code ---

using System;
using System.Linq.Expressions;

namespace MonoBug
   class Program
      public void testFunc() {}
      static void Main()
         Expression<System.Func<Program, Action>> action = (d => d.testFunc);

         // System.Delegate.CreateDelegate(System.Type, object,
         // Action.Body.Operand.Arguments[1].Value = (null)
         var actBody = (UnaryExpression)(action.Body);
         var methodCall = (MethodCallExpression)(actBody.Operand);
         var methodArg1 = (ConstantExpression)(methodCall.Arguments[1]);
             "Action.Body.Operand.Arguments[1].Value = {0}",
             methodArg1.Value ?? "(null)"

         // Compiling this code with csc.exe (.net Fx 3.5),
methodCall.Arguments[1] is result in ParameterExpression of "d". This behavior
is seemed to be expected.

         var t = action.Compile();
         Program p = new Program();

Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.

More information about the mono-bugs mailing list