How to force Monotouch AOT Compiler to see a nested generic method?
Asked Answered
N

1

25

I've had to jump through hoops, but I've almost managed to get ServiceStack working on iOS with Monotouch in my project. One runtime JIT exception is holding out:

System.ExecutionEngineException: Attempting to JIT compile method 'ServiceStack.Text.Json.JsonTypeSerializer:GetWriteFn<int> ()' while running with --aot-only. 

The offending code is quite simple:

   internal WriteObjectDelegate GetWriteFn<T>()
    {
        return JsonWriter<T>.WriteFn();
    }

As a test, I modified the SS code to make the internal methods and types public and included the following in the startup code of my project (to actually get called).

var ick = ServiceStack.Text.Json.JsonWriter<int>.WriteFn();
var erk = ServiceStack.Text.Json.JsonTypeSerializer.Instance.GetWriteFn<int>();

This still doesn't alert the AOT for some reason, I get the exception when the code above executes! Is this because the generic parameter is a value type? Or is it because these are static classes and methods? How can I force Monotouch to AOT the methods above?

The SS code in question is in JsonTypeSerializer.cs and JsonWriter.Generic.cs at: https://github.com/ServiceStack/ServiceStack.Text/tree/master/src/ServiceStack.Text/Json

Nunnery answered 11/12, 2012 at 23:49 Comment(2)
This looks strange. Can you file a bug at bugzilla.xamarin.com with a test case?Autarch
Having the same problem, the only way to serialize a list of ints is: var serializedData = "["+string.Join(",", Ids.ToArray())+"]";Cressy
T
1

There are some generic limitations in monotouch now. I think you should check your code to one of them.

Therapeutic answered 21/7, 2013 at 11:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.