Search Unity

Il2CPP Loading C# Assembly at runtime

Discussion in 'Android' started by jumboperson, Jul 22, 2016.

  1. jumboperson

    jumboperson

    Joined:
    Apr 17, 2013
    Posts:
    4
    I can't seem to get a C# assembly to load into an Il2Cpp android app. I decided to check out the libil2cpp.so which contains all compiled code and it appears that the assembly "loading" in il2cpp code just checks for the assemblies that were compiled with Il2Cpp and doesn't deal with loading anything else.

    I guess my question is will il2cpp support loading 3rd party C# assemblies at some point in the future or will all assemblies have to be il2cpp compiled?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @jumboperson

    IL2CPP is an ahead-of-time (AOT) compiler, so it needs to have access to all assemblies at compile time. I don't believe that we will ever support just-in-time (JIT) compilation with IL2CPP, so it won't support loading of 3rd party assemblies at runtime.

    Of course there could be other solutions for loading code at runtime besides a C# JIT that Unity will support in the future, but we don't have any plans for something like that now. If you need to load code at runtime, you should use the Mono scripting backend, which does support this scenario.
     
  3. jumboperson

    jumboperson

    Joined:
    Apr 17, 2013
    Posts:
    4
    @JoshPeterson

    In that case would this forum be the best place to ask about the compilation process of il2cpp or should I email with a technical inquiry? Because I was wondering if virtual functions of given objects are always at certain indexes or if these change/aren't used in some cases. For instance System.Reflection.Assembly::get_FullName() is at index 6 for the compilations I do of my own code, however when calling the function as such

    VirtualInvokeData vid = GetVirtualInvokeData(6, pAsm); // pAsm is of type Assembly_t*
    String_t* pName = vid.methodInfo->method(vid.target, (void*)vid.methodInfo);

    However my code never gets past the second line as in a cascaded call from the get_FullName function there is a seg fault. Perhaps I'm calling the wrong function?

    Edit: MethodInfo has a member for the name, I'll check that out, my bad.
     
    Last edited: Jul 25, 2016
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    @jumboperson

    In general, the index for virtual functions does not change from compilation to compilation of the same assembly. Once the assembly changes though, all bets are off, as the virtual table could have changed.
     
  5. jumboperson

    jumboperson

    Joined:
    Apr 17, 2013
    Posts:
    4
    @JoshPeterson

    Yeah, I was trying to use my own compilations of one assembly to approximate vtable indexes in an entirely different assembly. I've now just resorted to dumping the indexes.