Quick answer: Unity IL2CPP throwing MissingMethodException on a generic method that exists in source? Generic instantiations are stripped if no concrete usage - add explicit instantiation in link.xml or via [Preserve].
Generic JsonConvert.DeserializeObject<PlayerData> crashes on iOS. Compiles fine in editor.
Preserve the type and method
[Preserve]
static class Forcer {
static void _() {
JsonConvert.DeserializeObject<PlayerData>("");
}
}Compiler-visible concrete instantiation forces IL2CPP to emit the code.
Use link.xml
Specify the concrete generic in the linker. More verbose; works for cases where you can't modify source.
Drop generics on shipped boundaries
For API edges, accept JSON strings and Type. Internal callers do the casting. Generics are convenient; not always portable.
“Generics are tree-shaken by usage. No usage, no code.”
Test IL2CPP builds in CI on every release. The bugs are reproducible but not visible in editor; CI catches them before TestFlight does.