It says that using value types as dictionary keys will "crashes and burns rather quickly on the device", does that means I can't use something like Dictionary<int, string> to make a string lookup table?
It says that using value types as dictionary keys will "crashes and burns rather quickly on the device",
It's not so dramatic (no burn) or so automatic - but it can happen.
Apple does not allow JIT (just in time) compilation on devices. This means that everything must be pre-compiled (ahead of time) before being deployed to devices. This means a few limitations exists for MonoTouch that you would not have with .NET / Mono or Mono for Android.
In general the generated code for generics can be shared between different types. Sadly this is not possible for value types. This means the AOT (ahead of time) compiler must generate code for every value type being used.
In some cases the AOT compiler might not be able to detect every possible type that might be needed at runtime. This will cause an EngineExecutionException
that will point you to the offending code.
At this stage you can try to:
hint the AOT compiler that the code is needed (i.e. add some code that will make the AOT compiler generates the required missing code); or
refactor the code, e.g. to avoid value types;
does that means I can't use something like Dictionary to make a string lookup table?
No, that will work. When you create an instance of Dictionary<int, string>
then it's pretty straightforward for the AOT compiler to know what code needs to be generated.
Problems generally occurs when nesting generics or when using code that does (e.g. LINQ queries with value types can generate such code).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With