It seems that Assembly.GetModule(string moduleName) under IL2CPP (iOS simulator) doesn’t work (always returning null), while Assembly.GetModules() does return the expected list of modules of the assembly. Is this a bug?
This should work. Can you submit a bug report with a project that reproduces this issue? We would like to investigate it.
So the attached Unity project is created under Unity 2017.1.0f3 using the experimental .NET 4.6 runtime.
-
Assets/Editor/CreateAssembly.cs provides a way to create a very simple assembly “Test.dll”, with a dynamic module “Test” defined (as well as a public static TestType).
-
Assets/link.xml marks the assembly Test.dll to be fully included for IL2CPP transformation even though there is no explicit reference to it from runtime code (since we will use Reflection/Assembly to load it below)
-
Assets/Test.cs is a MonoBehavior that is attached to the Test GameObject which is put into the Test scene; the Start() method does Assembly.Load(), and performs Assembly.GetModule(name) and Assembly.GetModules() respectively
Under the UnityEditor, the Debug.Log output shows that both Assembly.GetMoudles() and Assembly.GetModule(“Test”) return the expected result
Then make an iOS simulator (SDK) build with IL2CPP transformation; open the generated Xcode project under Xcode, and run the iOS simulator project from within Xcode - in the output window, observe that Assembly.GetModules returns/prints [Test.dll], while Assembly.GetModule(“Test”) returns/prints nothing (due to returning null)
Notice that: Under an OSX build (mono), it also works as expected
Please help me verify if this is a bug or not. Thanks!
Forgot to use reply …
Yes, this is a bug. It should work.
Cool. Are you going to submit a bug on behalf of me? *** Thanks! ***
I’d prefer that you submit the bug report for two reasons. First, we can get the project exactly as you have it. Second, we can inform you when the bug is corrected. To submit a bug report, just look in the “Help” menu of the editor. It is pretty easy to do!
Thanks! We will investigate this.
https://issuetracker.unity3d.com/issues/il2cpp-assembly-dot-getmodule-string-returns-null: seems this is fixed for a “future” release?
The fix should land in the next patch release or two. You should be notified via the bug report when we know exactly which release will have the fix.