[MonoTouch] Another "Attempting to JIT compile method" Exception

Tim Scott tscott at lunaversesoftware.com
Sat Nov 28 14:18:04 EST 2009


The thing is, SetValue works fine if the property is DateTime type but not
if it¹s nullable DateTime.  I suspect it has to do with nullable types, or
more specifically generics, because nullable types are really Nullable<T>.
I will do some more testing to prove this out and report what I find.   In
any case, I would think that the static compilation should take care of this
for any property regardless of type.

This code illustrates what I am saying:

namespace ShowSetValueNullableDateTimeBug
{
    public class Application
    {
        static void Main (string[] args)
        {
            var propertyInfo = typeof(Foo).GetProperty("NullableDateTime");
            var foo = new Foo();
            try
            {
                propertyInfo.SetValue(foo, DateTime.Now, null);
                Console.WriteLine("Set value of nullable DateTime works!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }    
            
            propertyInfo = typeof(Foo).GetProperty("DateTime");
            foo = new Foo();
            try
            {
                propertyInfo.SetValue(foo, DateTime.Now, null);
                Console.WriteLine("Set value of DateTime works!");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }      
            
            UIApplication.Main (args);
        }
    }
    
    public class Foo
    {
        public DateTime DateTime { get; set; }
        public DateTime? NullableDateTime { get; set; }
    }

    public partial class AppDelegate : UIApplicationDelegate
    {
        public override bool FinishedLaunching (UIApplication app,
NSDictionary options)
        {
            window.MakeKeyAndVisible ();
            return true;
        }

        public override void OnActivated (UIApplication application)
        {
        }
    }
}


On 11/28/09 12:39 PM, "Miguel de Icaza" <miguel at novell.com> wrote:

> Hello Tim,
> 
>> var propertyInfo = typeof(Foo).GetProperty("SomeNullableDateTimeProperty");
>> var foo = new Foo();
>> propertyInfo.SetValue(foo, DateTime.Now, null);
>> 
>> I get an exception:
>> 
>> System.Reflection.TargetInvocationException:
>> Exception has been thrown by the target of an invocation. --->
>> System.ExecutionEngineException: Attempting to JIT compile method
>> '(wrapper runtime-invoke)
> 
> The reason for this is that the static compiler did not have visibility into
> the class that you are trying to invoke, in this case, it is the trampoline
> code that allows the SetValue to work.
> 
> I'll discuss with the team if this can be statically inferred, but it does
> seem difficult, as the information could be anything.
> 
> Miguel
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/monotouch/attachments/20091128/b07e76b5/attachment.html 


More information about the MonoTouch mailing list