Search Unity

Resolved IL2CPP results in corrupted build.

Discussion in 'Scripting' started by blablaalb, Aug 18, 2021.

  1. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    The application I'm developing needs to get metadata, such as thumbnail, artist, album etc, from audio files. In order to obtain the meta I use plugin taglib sharp. The plugin works perfectly fine when I build with mono, but after I switch the backend to IL2CPP I get runtime
    Constructor on type 'TagLib.Riff.File' not found
    exception.
    I have no clue what to do now. How can I make it work? If the Mono supported ARM64, I would just build with Mono.
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    I suspect that managed code stripping is removing the constructor for this type since it is likely used only via reflection.

    Managed code stripping is disabled by default for Mono, but is enabled for IL2CPP. You can indicate to the managed code stripping system that you don't want it to remove code from a given assembly or for a given type or method specifically. See https://docs.unity3d.com/Manual/ManagedCodeStripping.html for details.
     
  3. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    @JoshPeterson, It's been couple of hours since I'm trying to resolve this issue using managed code stripping and can't make it working.
    The link.xml is located under the Assets folder.
    This is its content:
    Code (xml):
    1. <linker>
    2.        <assembly fullname="TagLib">
    3.               <type fullname="TagLib.Riff.File" preserve="all"/>
    4.        </assembly>
    5.  
    6.        <assembly fullname="TagLib.Riff">
    7.               <type fullname="TagLib.Riff.File" preserve="all"/>
    8.        </assembly>
    9.  
    10.        <assembly fullname="TagLib.Riff">
    11.               <type fullname="TagLib.File" preserve="all"/>
    12.        </assembly>
    13.  
    14.        <assembly fullname="TagLib">
    15.               <type fullname="TagLib.File" preserve="all"/>
    16.        </assembly>
    17. </linker>
    18.  
    The exception points to TagLib.Riff.File, but in the code the full reference to the File is TagLib.File
    upload_2021-8-18_15-57-10.png

    Not sure how to configure the link.xml to make it working
    Is it possible to disable stripping for a whole dll file?
     

    Attached Files:

  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,938
    Yes this should work:
    1. <linker>
    2. <assembly fullname="TagLib" preserve="all"/>
    3. </linker>
    This assumes the name of the assembly is TabLib.dll.
     
    DhiaSendi likes this.
  5. blablaalb

    blablaalb

    Joined:
    Oct 28, 2015
    Posts:
    53
    I got it working: the assmebly turned out to be taglib-sharp
    This is the working link.xml
    Code (xml):
    1. <linker>
    2.        <assembly fullname="taglib-sharp">
    3.               <type fullname="TagLib.Riff.File" preserve="all"/>
    4.        </assembly>
    5.  
    6.        <assembly fullname="taglib-sharp">
    7.               <type fullname="TagLib.File" preserve="all"/>
    8.        </assembly>
    9. </linker>
     
    DhiaSendi and JoshPeterson like this.
  6. DhiaSendi

    DhiaSendi

    Joined:
    May 16, 2018
    Posts:
    43
    In my case, I got an error related to 'TagLib.Mpeg.AudioFile'
    So I made a small change to the .XML file provided by @blablaalb (Thanks)

    Code (CSharp):
    1. <linker>
    2.        <assembly fullname="TagLibSharp">
    3.               <type fullname="TagLib.Riff.File" preserve="all"/>
    4.        </assembly>
    5.        <assembly fullname="TagLibSharp">
    6.               <type fullname="TagLib.File" preserve="all"/>
    7.        </assembly>
    8.      
    9.         <assembly fullname="TagLibSharp">
    10.               <type fullname="TagLib.Mpeg.AudioFile" preserve="all"/>
    11.        </assembly>
    12.  
    13. </linker>