iOS Reflection Code stripping problem

Hi all,

I’ve written a small system (node scripting) which invokes functions from different types dynamically, and this works great on most platforms, except iOS.

On Android/Standalone, when I check a reflected type with “GetMethods()”, I can iterate through and see every method available.
However on iOS, I can’t invoke any of the methods I want to, as “GetMethods()” returns 0 results on the same reflected type. And I’ve made sure that the type was found, etc.

The method I’m trying to dynamically invoke in this situation is the static “SceneManager.LoadScene(int)”, under “UnityEngine.SceneManagement”.

I’m pretty sure it’s a linking/stripping problem.
Due to none of these namespaces/types ever being directly written into the source code, and it’s all called dynamically, I’m sure the code stripping is removing what it thinks isn’t being used.

But even when I disable code stripping, and I add the “Link.xml” file, which preserves all the namespaces I want to use, I still have the same problem. (Just now with a much larger final build).

I’ve managed to create workarounds for a lot of the JIT/AOT related problems from IL2CPP, but this simple issue is crippling my project.
Literally everything else works, except apparently this function doesn’t exist in the stripped end product.

Thanks in advance to anyone who can potentially help me out with this problem.

Future note for anyone interested:

If you’re creating a link.xml file, “Type” doesn’t work unless it is UNDER an “Assembly”…
I read and re-read that docs, and that didn’t seem major, and I kept missing it.

<Assembly> uses "Fullname"  
    <Type> uses "Fullname" and "Preserve"  
        <Method> uses "Name"  

Any other attributes or layout basically disables it, or throws an error from what I’ve found.
I originally just wanted to avoid stripping of a few types, but it requires being under the assembly tags.

I tried to simply preserve the entire Unity Assembly just to quickly check if it was a stripping issue.
That does not work!

Specify exactly what you want using the above tags/attributes.

  • Peace

Damn, that’s nasty! I implemented a saving system based on reflection and well … you can imagine the rest.

Turns out to avoiding code stripping on members can be achieved much simpler, by just adding some strong references to the stripped methods/properties/fields.

In my case I implemented a Behavior that just sets some properties to their own values. This behavior is only used in one level that basically just contains this script. I build this level, but never actually load it.

using UnityEngine;

public class PreserveAssembly : MonoBehaviour
	public SomeBehavior someBehavior;

	void Start()
		someBehavior.someField = someBehavior.someField;
		transform.eulerAngles = transform.eulerAngles;

SomeBehavior is an other Behavior where I want to use reflection on its property someField.