Search Unity

Resolved IL2CPP vs Mono problem

Discussion in 'Editor & General Support' started by Venushja, Apr 7, 2023.

  1. Venushja

    Venushja

    Joined:
    Apr 16, 2019
    Posts:
    7
    Hello, Since I have reached the point where I am working on a release, I have switched to the il2cpp compiler and found that a portion of my code is not working. The issue is with the method "FileVersionInfo.GetVersionInfo(path)", which works fine and loads the data without any problem when built with mono, but when built with il2cpp, it returns null values. Has anyone else encountered this issue and how can it be resolved?

    Thanks

    Unity version: 2019.4.15f1

    I have created a test application to verify that the issue is indeed with the build and not a problem with the code.
    Mono:
    mono.png
    il2pp: il2cpp.png
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,752
    Most likely IL2CPP doesn't implement this method / class. It exists in
    System.Diagnostics
    and IL2CPP doesn't implement
    Process
    either, which also exists in System.Diagnostics.

    Here's some details on possible workarounds with a native integration:

    https://forum.unity.com/threads/solved-il2cpp-and-process-start.533988/

    Keep in mind in a build you would never use System.IO calls to load Unity-provided assets because the entire file hierarchy of your game is collapsed into a runtime database. If you're doing this it will only ever work in the editor, in which case you don't need it to work in IL2CPP
     
    Venushja likes this.
  3. Venushja

    Venushja

    Joined:
    Apr 16, 2019
    Posts:
    7
    Thanks a lot for the direction. I solved it via DLLImport it also works in il2cpp build.

    Code (CSharp):
    1. DllImport("version.dll", CharSet = CharSet.Unicode)]
    2. private static extern int GetFileVersionInfoSize(string lptstrFilename, out uint lpdwHandle);
    3. [DllImport("version.dll", CharSet = CharSet.Unicode)]
    4. private static extern bool GetFileVersionInfo(string lptstrFilename, uint dwHandle, uint dwLen, IntPtr lpData);
    5. [DllImport("version.dll", CharSet = CharSet.Unicode)]
    6. private static extern bool VerQueryValue(IntPtr pBlock, string lpSubBlock, out IntPtr lplpBuffer, out uint puLen);
    7.  
    8. uint handle;
    9. int size = GetFileVersionInfoSize(path, out handle);
    10. if (size > 0)
    11. {
    12.     IntPtr buffer = Marshal.AllocHGlobal(size);
    13.     if (GetFileVersionInfo(path, handle, (uint)size, buffer))
    14.     {
    15.         IntPtr pValue;
    16.         uint len;
    17.         if (VerQueryValue(buffer, "\\StringFileInfo\\040904b0\\FileVersion", out pValue, out len))
    18.         {
    19.             string fileVersion = Marshal.PtrToStringUni(pValue);
    20.             Debug.Log("File Version: " + fileVersion);
    21.         }
    22.     }
    23.     Marshal.FreeHGlobal(buffer);
    24. }
     
    Last edited: Apr 7, 2023
    Kurt-Dekker likes this.