Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

How to pass --extra-types-file parameters to il2cpp.exe?

Discussion in 'Documentation' started by heffendy, Aug 3, 2018.

  1. heffendy

    heffendy

    Joined:
    Aug 3, 2018
    Posts:
    3
    I'm looking at explicitly specify some value type to an generic type (which is an internal type of an external component) via il2cpp_extra_types.txt as suggested here:
    https://forum.unity.com/threads/il2cpp-type-makegenerictype-work-around.311926/

    However, simply putting the il2cpp_extra_types.txt file in the Assets folder did not work and from the logs, it appears that the issue is the il2cpp_extra_types.txt filepath didn't get passed along to il2cpp.exe (I also notice it did not pick up Data/il2cpp/il2cpp_default_extra_types.txt).

    Here's the arguments according to the log file:

    Invoking il2cpp with arguments: --convert-to-cpp --emit-null-checks --enable-array-bounds-check --dotnetprofile="unityjit" --map-file-parser="C:\Program Files\Unity\Hub\Editor\2018.1.5f1\Editor\Data\Tools\MapFileParser\MapFileParser.exe" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.CJK.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.MidEast.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.Other.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.Rare.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\I18N.West.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\UnityEngine.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\Autofac.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\mscorlib.dll" --assembly="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Data\Managed\System.dll" --generatedcppdir="F:\Source\Repos\MyProject\MyProject.Unity\Temp\StagingArea\Il2CppOutputProject\Source\il2cppOutput"

    I'm on 2018.1.5f1 which I verified the il2cpp.exe supports the --extra-types-file option.

    Any ideas on how this can be configured correctly?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,380
    I don't think the extra types file is supported any longer, and I thought that command line option was removed (although I might be wrong, it seems). I would not recommend that approach anyway. Maybe we can determine the cause of the issue and correct it. What is the original problem?
     
  3. heffendy

    heffendy

    Joined:
    Aug 3, 2018
    Posts:
    3
    Hi Josh,

    Interestingly I didn't find the --extra-types-file option on Unity2017.4.2f2 but saw that it came back on Unity2018.1.5f1 and assume there are changes on how this gets consumed.


    So the original issue is that we're hitting an ExecutionEngineException related to our usage of AutoFac's Keyed Service feature.

    Specifically, IL2CPP only generated the code for reference types:

    Autofac.Features.Indexed.KeyedServiceIndex`2<System.Object,System.Object>


    Our usage, however, is that we're using a value type (i.e. an enum) as the key and hence require the following to get generated:

    Autofac.Features.Indexed.KeyedServiceIndex`2<MyEnum,System.Object>


    Unfortunately, since KeyedServiceIndex is an internal type to the AutoFac assembly, we were not able to work around it by simply adding dummy code that new up the concrete type to hint to IL2CPP.

    Modifying AutoFac to expose the type so that we can do the above is an alternative but I was really hoping to leverage a generic solution like Il2cpp_extra_types.txt to be able to hint to IL2CPP without requiring code changes. Especially since there's an equivalent concept of TypeInstantiation in .NET Native.


    In this particular case, I think we would be able to work around it by changing our usage of the key to a string (MyEnum.ToString()) instead of the enum directly so that the reference types version would be used.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    3,380
    Thanks for the details. I think your best option now is to use the key as a string. We'll consider providing better support for the extra types file though, as it still may be useful in some cases.

    Note that in Unity 2018.3 this problem should go away, since we've added support for generic sharing with enums. This means IL2CPP will be able to handle enum types as generic arguments like this, even when it does not have knowledge of those full generic types at compile time.

    The 2018.3 public beta releases should start soon, I'd recommend giving them a try, at least to confirm that my understanding is correct.