[MonoTouch] Another "Attempting to JIT compile method" Exception
Tim Scott
tscott at lunaversesoftware.com
Sat Nov 28 14:53:10 EST 2009
The issue is indeed with nullables (possibly with any generic). The
following code and output shows this.
Here¹s the code:
namespace ShowSetValueNullableBug
{
public class Application
{
static Foo foo = new Foo();
static void Main (string[] args)
{
TrySetValue<string>("String");
TrySetValue<int>("Int");
TrySetValue<bool>("Bool");
TrySetValue<DateTime>("DateTime");
TrySetValue<decimal>("Decimal");
TrySetValue<double>("Double");
TrySetValue<long>("Long");
TrySetValue<byte>("Byte");
TrySetValue<float>("Float");
TrySetValue<char>("Char");
TrySetValue<short>("Short");
TrySetValue<uint>("UInt");
TrySetValue<ulong>("ULong");
TrySetValue<ushort>("UShort");
TrySetValue<MyEnum>("Enum");
TrySetValue<TimeSpan>("TimeSpan");
TrySetValue<int?>("NullableInt");
TrySetValue<bool?>("NullableBool");
TrySetValue<DateTime?>("NullableDateTime");
TrySetValue<decimal?>("NullableDecimal");
TrySetValue<double?>("NullableDouble");
TrySetValue<long?>("NullableLong");
TrySetValue<byte?>("NullableByte");
TrySetValue<char?>("NullableChar");
TrySetValue<short?>("NullableShort");
TrySetValue<uint?>("NullableUInt");
TrySetValue<ulong?>("NullableULong");
TrySetValue<ushort?>("NullableUShort");
TrySetValue<TimeSpan?>("NullableTimeSpan");
TrySetValue<MyEnum>("NullableEnum");
UIApplication.Main (args);
}
private static void TrySetValue<T>(string propertyName)
{
var propertyInfo = typeof(Foo).GetProperty(propertyName);
try
{
propertyInfo.SetValue(foo, default(T), null);
Console.WriteLine(string.Format("Set value of {0}
succeeds!", propertyName));
}
catch (Exception ex)
{
Console.WriteLine(string.Format("Set value of {0} FAILS!",
propertyName));
}
}
}
public class Foo
{
public string String { get; set; }
public int Int { get; set; }
public bool Bool { get; set; }
public DateTime DateTime { get; set; }
public decimal Decimal { get; set; }
public double Double { get; set; }
public long Long { get; set; }
public byte Byte { get; set; }
public float Float { get; set; }
public char Char { get; set; }
public short Short { get; set; }
public uint UInt { get; set; }
public ulong ULong { get; set; }
public ushort UShort { get; set; }
public MyEnum Enum { get; set; }
public TimeSpan TimeSpan { get; set; }
public int? NullableInt { get; set; }
public bool? NullableBool { get; set; }
public DateTime? NullableDateTime { get; set; }
public decimal? NullableDecimal { get; set; }
public double? NullableDouble { get; set; }
public long? NullableLong { get; set; }
public byte? NullableByte { get; set; }
public float? NullableFloat { get; set; }
public char? NullableChar { get; set; }
public short? NullableShort { get; set; }
public uint? NullableUInt { get; set; }
public ulong? NullableULong { get; set; }
public ushort? NullableUShort { get; set; }
public TimeSpan? NullableTimeSpan { get; set; }
public MyEnum? NullableEnum { get; set; }
}
public enum MyEnum
{
One
}
public partial class AppDelegate : UIApplicationDelegate
{
public override bool FinishedLaunching (UIApplication app,
NSDictionary options)
{
window.MakeKeyAndVisible ();
return true;
}
public override void OnActivated (UIApplication application)
{
}
}
}
And here is the output:
Set value of String succeeds!
Set value of Int succeeds!
Set value of Bool succeeds!
Set value of DateTime succeeds!
Set value of Decimal succeeds!
Set value of Double succeeds!
Set value of Long succeeds!
Set value of Byte succeeds!
Set value of Float succeeds!
Set value of Char succeeds!
Set value of Short succeeds!
Set value of UInt succeeds!
Set value of ULong succeeds!
Set value of UShort succeeds!
Set value of Enum succeeds!
Set value of TimeSpan succeeds!
Set value of NullableInt FAILS!
Set value of NullableBool FAILS!
Set value of NullableDateTime FAILS!
Set value of NullableDecimal FAILS!
Set value of NullableDouble FAILS!
Set value of NullableLong FAILS!
Set value of NullableByte FAILS!
Set value of NullableChar FAILS!
Set value of NullableShort FAILS!
Set value of NullableUInt FAILS!
Set value of NullableULong FAILS!
Set value of NullableUShort FAILS!
Set value of NullableTimeSpan FAILS!
Set value of NullableEnum FAILS!
On 11/28/09 1:18 PM, "Tim Scott" <tscott at lunaversesoftware.com> wrote:
> 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/1359a6d4/attachment-0001.html
More information about the MonoTouch
mailing list