Search Unity

  1. Unity Asset Manager is now available in public beta. Try it out now and join the conversation here in the forums.
    Dismiss Notice

Bug Missing method on IL2CPP build

Discussion in '2021.2 Beta' started by Kunnogi, Jun 15, 2021.

  1. Kunnogi

    Kunnogi

    Joined:
    Apr 29, 2019
    Posts:
    12
    When using 2021.2.0a20 and building using IL2CPP, if you use interop services, at the time of its disposal it finds a missing method (that should be located at mscorlib?), using link.xml to bypass stripping dont helps and the problem persists. Can be easily reproducible by using mono sqlite and trying to close a connection.
    Code (CSharp):
    1. System.MissingMethodException: System.Runtime.InteropServices.Marshal::SetLastWin32Error(System.Int32)
    2.   at System.Runtime.InteropServices.CriticalHandle.Dispose (System.Boolean disposing) [0x00000] in <00000000000000000000000000000000>:0
    3.   at System.Runtime.InteropServices.SafeHandle.Dispose () [0x00000] in <00000000000000000000000000000000>:0
    4.   at Mono.Data.Sqlite.SQLite3.Close () [0x00000] in <00000000000000000000000000000000>:0
    5.   at Mono.Data.Sqlite.SQLite3.Dispose (System.Boolean bDisposing) [0x00000] in <00000000000000000000000000000000>:0
    6.   at Mono.Data.Sqlite.SqliteConnection.Dispose (System.Boolean disposing) [0x00000] in <00000000000000000000000000000000>:0
    7.   at System.ComponentModel.Component.Dispose () [0x00000] in <00000000000000000000000000000000>:0
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
  3. Kunnogi

    Kunnogi

    Joined:
    Apr 29, 2019
    Posts:
    12
    I did send it, is there anyway i can make the method to work for now? Even if i do try catch (given its at close that the problem happens) i still cant use it (i was using 2020 LTS and it was working 100% fine), if i dispose any of the related stuff it gives error on the same place.
     
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I'm not sure, sorry. We will need to investigate the bug report to learn more.
     
  5. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    The missing method on IL2CPP indeed seems to be the problem (still). Is there any update on this?
     
    Baydogan and vasildx like this.
  6. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I don't recall what the bug report number was for this one, so I'm not sure, sorry!
     
  7. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    @LeonhardP Kindly pointed me to the bug report that was originally submitted for this issue. Unfortunately, our QA team could not reproduce it, so we did not take any action.

    @jirimotejlek If you have a Unity project that will reproduce this issue that you can submit via a bug report, please do so. We would love to investigate this issue. Thanks!

    https://unity3d.com/unity/qa/bug-reporting
     
  8. jirimotejlek

    jirimotejlek

    Joined:
    Nov 8, 2016
    Posts:
    20
    After experimenting with this the whole day, I suspect that I (and potentially @Kunnogi) are not using the correct libsqlite3.so or Mono.Data.Sqlite.dll compatible with the current 2021.2.0f version and it's causing this problem. In my case, I can't open the connection to the database, receiving the same error as @Kunnogi - System.MissingMethodException: etc..) It worked correctly in 2021.1 as well as all 2020 versions.

    Which Mono.Data.Sqlite.dll and libsqlite3.so should be used? Is there any guidance regarding how to set this this up?
    It's not like SQLite is some obscure tool, it's the most widely used embedded database in the world. Yet, there is literally hundreds of different posts on unity.com forums as well as elsewhere from devs struggling to make it work in Unity3D.

    Can this be, for example, a package that the developer would install if they need sqlite support in their game?
     
  9. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    We don't have any documentation or guidance about the usage of SQLite from the Unity side. I think that Mono.Data.Sqlite.dll should work, but it is not something that we actively test with Unity either, so I can't say for sure.

    I suspect that would be possible. I'm not familiar with what C# bindings there are already for SQLite, but I see no reason why there could not be a Unity package which makes this work well.
     
  10. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    Hi!Someone managed to solve this problem on version 2021.2 ?
     
    Baydogan likes this.
  11. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    Hi all,

    any news?

    Thanks
     
    Baydogan likes this.
  12. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    Hi! I have updated the unit to version 2021.2.4f1 and replaced Mono.Data.Sqlite.dll with sources
     

    Attached Files:

  13. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
  14. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
  15. TudorA

    TudorA

    Joined:
    Jan 3, 2017
    Posts:
    3
    @xAvatarchikx Did you add them to the Plugins folder ? It seems I get some compilation problems.
     
  16. xAvatarchikx

    xAvatarchikx

    Joined:
    Aug 17, 2012
    Posts:
    69
    you still need to create a file csc.rsp in the Assets folder
    and add a line to it
    -r:System.Transactions.dll
     
  17. TudorA

    TudorA

    Joined:
    Jan 3, 2017
    Posts:
    3
    @xAvatarchikx Thank you for your response, the compilation errors are gone :).Somehow in my case the android build, still expects the dll when running on the phone.
     
  18. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    Hi,

    @xAvatarchikx, I have added the sources you mentioned (in /Assets/Plugins/Mono.Data.Sqlite_2.0/), csc.rsp included in Assets. I have created an assembly definition with a name Mono.Data.Sqlite in the root folder of the sources.

    It compiles and build with no issues but at run-time I have got these errors:

    From Playing in Editor
    - EntryPointNotFoundException: sqlite3_libversion_number assembly:<unknown assembly> type:<unknown type> member:(null)

    From running on the mobile:

    - The type initializer for 'Mono.Data.Sqlite.UnsafeNativeMethods' threw an exception
    - Unable to load DLL 'Mono.Data.Sqlite.DLL'. Tried the load the following dynamic libraries: Unable to load dynamic library 'Mono.Data.Sqlite.DLL' because of 'Failed to open the requested dynamic library (0x06000000) dlerror() = dlopen failed: library "Mono.Data.Sqlite.DLL" not found (from running on the mobile)

    Am I missing something?
     
  19. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    Btw, I am using unity 2021.2.5f1 ...
     
  20. RRvfx

    RRvfx

    Joined:
    Jun 14, 2018
    Posts:
    25
    this seems the right choice:
    https://github.com/praeclarum/sqlite-net

    it seems working everywhere... tested quickly on editor, standalone and android (on mobile)...

    May someone confirm with my (quick) test? It would be really appreciated...

    Thanks
     
  21. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I am using unity 2021.2.6, and this bug still exists.

    Any Update on this Issue?
     
    Last edited: Dec 22, 2021
  22. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
  23. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
  24. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
  25. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I am using unity 2021.2.7, and this bug still exists.

    I have tried everything, even installing a virtual machine and clean install unity.

    Nothing worked.

    @JoshPeterson Please take another look at the submitted bug, or I can fill another bug report with an example project.
     
    pKallv and Directionality like this.
  26. Directionality

    Directionality

    Joined:
    Jul 8, 2017
    Posts:
    5
    Hey Baydogan,

    I'm also using Mono.Data.Sqlite, and ran into the exact same issue trying to use it on Android after the engine upgrade. I found a workaround that's admittedly kinda hacky, but I'll share it so we have a way forward until this gets fixed :)

    After much digging, I was able to get things working again by adding a bogus definition for
    Marshal.SetLastWin32Error
    inside the IL2CPP files, rebooting, and deleting the Library/Temp folders and rebuilding. This was my first time digging into the IL2CPP internals, so I'm not totally sure which of the attached changes ended up patching things, but I ended up editing six files (the root folder is Unity/Hub/Editor/<version>/Editor/Data):

    • il2cpp/external/mono/mono/metadata/icall-def.h
    • il2cpp/external/mono/mono/metadata/marshal.c
    • il2cpp/external/mono/mono/metadata/marshal.h
    • il2cpp/libil2cpp/icalls/mscorlib/System.Runtime.InteropServices/Marshal.cpp
    • il2cpp/libil2cpp/icalls/mscorlib/System.Runtime.InteropServices/Marshal.h
    • il2cpp/libil2cpp/libil2cpp.icalls
    I'm attaching a patch file containing all the changes I made, along with the updated files. Like I said, this is a bit hacky and is meant to just be a temporary workaround, so hopefully we get an official resolution to this later!
     

    Attached Files:

    jacksonkr, wbourchier and Baydogan like this.
  27. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
  28. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    @Directionality

    I am getting this error.

    Classes/Native/mscorlib17.cpp:21301:129: No member named 'SetLastWin32Error' in 'il2cpp::icalls::mscorlib::System::Runtime::InteropServices::Marshal'; did you mean 'GetLastWin32Error'?
     
  29. Directionality

    Directionality

    Joined:
    Jul 8, 2017
    Posts:
    5
    @Baydogan
    You probably missed updating one of the files. If you like, DM me and we can look over your setup sometime. Also, make sure you delete Library/Temp before rebuilding!
     
  30. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    Thank for the fast response, I am trying again.

    BTW my configuration is

    Apple Silicon M1 Max / Mac Os Monterey 12.0.1 / Unity 2021.2.7f1 Apple Silicon / API LEVEL .Net Framework

    I am building for iOs.
     
  31. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    After investigating my iOs build problem with Directionality.

    I realized I also have to modify these files.

    /Applications/Unity/Hub/Editor/2021.2.7f1/PlaybackEngines/iOSSupport/il2cpp/libil2cpp/include/icalls/mscorlib/System.Runtime.InteropServices/Marshal.h
    /Applications/Unity/Hub/Editor/2021.2.7f1/PlaybackEngines/iOSSupport/il2cpp/libil2cpp/include/libil2cpp.icalls


    But my exported xcode project still does not build. Only fails with a different error.



    @Directionality Thanks for your help, you are great.
     
    Last edited: Dec 28, 2021
  32. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I have just downloaded the version 2022.1.0b2 and run "grep "SetLastWin32Error" -R ." for the root app folder.
    And I also did the same for version 2021.2.6f1.
    Then I have compared the results.

    There are three new files which contains the word "SetLastWin32Error". o_O





    ./Unity.app/Contents/il2cpp/external/mono/mono/metadata/icall-def.h
    :NOHANDLES(ICALL(MARSHAL_29a,"SetLastWin32Error",ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error))

    ./Unity.app/Contents/il2cpp/external/mono/mono/metadata/marshal.c
    :ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error (guint32 err)

    ./Unity.app/Contents/il2cpp/external/mono/mono/metadata/marshal.h
    :ves_icall_System_Runtime_InteropServices_Marshal_SetLastWin32Error (guint32 err);


     
  33. Directionality

    Directionality

    Joined:
    Jul 8, 2017
    Posts:
    5
    So this might be fixed in the upcoming release? Wild.
     
  34. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I hope so.
     
  35. unity_56399AB65F28AE01D1DA

    unity_56399AB65F28AE01D1DA

    Joined:
    Dec 18, 2021
    Posts:
    7
    Hi team,

    I have used SQLite for the functioning of a game made with Unity 2020.3.8f1. It worked fine in both: Windows and Android OS (IL2CPP and Mono build). However, I am getting the below issue when trying to run the same app on iOS platform. I believe I have set everything correctly for the app to work. Can you please go through the part of the log below and let me know how to have it fixed :

    MissingMethodException: System.Runtime.InteropServices.Marshal::SetLastWin32Error(System.Int32)

    at System.Runtime.InteropServices.CriticalHandle.Cleanup () [0x00000] in <00000000000000000000000000000000>:0

    at System.Runtime.InteropServices.CriticalHandle.Dispose (System.Boolean disposing) [0x00000] in <00000000000000000000000000000000>:0

    at System.Runtime.InteropServices.CriticalHandle.Dispose () [0x00000] in <00000000000000000000000000000000>:0

    at Mono.Data.Sqlite.SQLite3.Close () [0x00000] in <00000000000000000000000000000000>:0

    at Mono.Data.Sqlite.SqliteConnection.Close () [0x00000] in <00000000000000000000000000000000>:0

    at Mono.Data.Sqlite.SqliteConnection.Dispose (System.Boolean disposing) [0x00000] in <00000000000000000000000000000000>:0

    at System.ComponentModel.Component.Dispose () [0x00000] in <00000000000000000000000000000000>:0
     
  36. Directionality

    Directionality

    Joined:
    Jul 8, 2017
    Posts:
    5
    It's the same issue we've been having where Marshal.SetLastWin32Error seems not to be defined in the IL2CPP files. @Baydogan did you get your iOS build up and running?
     
  37. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
  38. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    @Directionality

    Finally I have found a workaround until unity fixes this bug.

    1. Don't modify any unity editor file. Just build for iOS as usual.
    3. Search for "// System.Void System.Runtime.InteropServices.CriticalHandle::Cleanup()" on xcode project.
    4. Move a few lines below and comment out the line that starts with : "Marshal_SetLastWin32Error_"
    5. DONE


    example:


    IL_002b:
    { il2cpp_codegen_runtime_class_init_inline(Marshal_tD976A56A90263C3CE2B780D4B1CADADE2E70B4A7_il2cpp_TypeInfo_var);
    // Marshal_SetLastWin32Error_mC871D8DAC36418FAA95AFD23CD2A3ECC94628D1C(G_B6_0, NULL); il2cpp_codegen_runtime_class_init_inline(GC_t920F9CF6EBB7C787E5010A4352E1B587F356DC58_il2cpp_TypeInfo_var);
    GC_SuppressFinalize_m3352E2F2119EB46913B51B7AAE2F217C63C35F2A(__this, NULL);
    return;
    }
    }
     
    pKallv likes this.
  39. unity_56399AB65F28AE01D1DA

    unity_56399AB65F28AE01D1DA

    Joined:
    Dec 18, 2021
    Posts:
    7

    Hi, can you let me know in which file were you able to find such part of the code?
     
  40. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    I have explained it step by step.

    Did you follow the steps?

    In my build the code that I commented out was inside a file named mscorlib17.cpp.
     
    Last edited: Jan 3, 2022
    pKallv likes this.
  41. unity_56399AB65F28AE01D1DA

    unity_56399AB65F28AE01D1DA

    Joined:
    Dec 18, 2021
    Posts:
    7
    Yeah, figured it out later on. I was not able to find that line of code initially.

    You are a gem ! Thanks a lot for sharing the information on how to have that issue fixed. Game works as expected now on iPhone.

    I am very new to this system, I have worked on making apps for android but never for iOS, so xcode, provisioning profile etc were already completely new to me and after going through all of that it felt bad when the game did not function as expected on iPhone.
     
  42. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    Glad it worked. This issue literally made me crazy.

    Also lack of response from unity people is heartbreaking :(
    I think it is because of the xmas and holidays.
     
    pKallv likes this.
  43. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    You are my hero, a BIG thank you. I have been struggling with this for quite some time now.
     
    Baydogan likes this.
  44. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    @pKallv My friend I know your pain :) Glad I helped. Have a nice day.
     
    pKallv likes this.
  45. pKallv

    pKallv

    Joined:
    Mar 2, 2014
    Posts:
    1,191
    Just wondering is this a problem with uploading to Android as well?
     
  46. Baydogan

    Baydogan

    Joined:
    Mar 22, 2018
    Posts:
    54
    @pKallv I think @Directionality encountered this problem while he was trying to build for android. So I guess this bug also affects android builds.
     
    pKallv likes this.
  47. Directionality

    Directionality

    Joined:
    Jul 8, 2017
    Posts:
    5
    Nice find!
    Yeah, I'm not sure why the previous fix defining SetLastWin32Error worked for us in our Android build, but not iOS; removing the call from the CriticalHandle finalizer also seems like a fine workaround though.

    Of course it would be nifty to have the CriticalHandle finalizer work as expected by having that method resolvable at runtime, Unity :)
     
    Baydogan likes this.
  48. wbourchier

    wbourchier

    Joined:
    Feb 4, 2018
    Posts:
    6
    This appears to still be a problem in 2021.2.8
     
  49. wbourchier

    wbourchier

    Joined:
    Feb 4, 2018
    Posts:
    6
    Thanks very much @Directionality for taking the time to so clearly articulate a workaround, got me moving again.

    Can't find the issue in the unity issue tracker, there seem to be a lot of IL2CPP issues in 2021.2.X haha, does anyone have the link to the original issue so we can check if it's still active, although @JoshPeterson did imply they couldn't recreate it so closed it down.

    I have a super simple project that I can upload to bug reporting to get this back on Unity's radar if necessary.
     
    pKallv likes this.
  50. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes, please submit a bug report for this issue, we would love to understand and correct it.