Search Unity

IL2CPP error for type 'System.String'

Discussion in 'Windows' started by Steve2375, Jan 9, 2021.

  1. Steve2375

    Steve2375

    Joined:
    Mar 28, 2015
    Posts:
    42
    I get this error when I build my project for IL2CPP (Mono works fine):

    Exception: IL2CPP error for type 'System.String' in assembly 'E:\Projects\MyProject\Temp\StagingArea\Data\Managed\mscorlib.dll'
    System.NotSupportedException: IL2CPP does not support attributes with object arguments that are array types.

    It is a rather large project, I am sure I need to adjust parts to work with IL2CPP but I cannot find the root problem from the error message. Can anybody help me with that?
     
  2. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    That is a pretty bad error message, unfortunately. It should point to the part of the project that has the issue. Can you submit a bug report and include this project, by chance? We could examine it and let you know what the offending code is, as well as improve that error message.
     
    msklayaci likes this.
  3. Steve2375

    Steve2375

    Joined:
    Mar 28, 2015
    Posts:
    42
    After some trial and error I found the problem: we are using attributes like that
    Code (CSharp):
    1. [DefaultValue(new int[2] { 2, 5 })]
    2. public int[] Variable { get; set; }
    for a yaml serializer. So the first line of the error is totally misleading.

    Is it true that IL2CPP does not support attributes like that? Is there any replacement or configuration for IL2CPP so I can use these attributes?
     
    Last edited: Jan 12, 2021
  4. JoshPeterson

    JoshPeterson

    Unity Technologies

    Joined:
    Jul 21, 2014
    Posts:
    6,936
    Yes, IL2CPP does not support an attribute with an argument type of object. What is the definition of DefaultValueAttribute? If it can be changed to have a constructor the accepts an int[], then I think this will work.

    And yes, the error message here is not helpful. I'll see if I can improve it.
     
  5. Steve2375

    Steve2375

    Joined:
    Mar 28, 2015
    Posts:
    42
    Ok thanks. I created a sub class of the Attribute class that defines specific constructors for my usage, like that

    Code (CSharp):
    1. public class ArrayDefaultValueAttribute : DefaultValueAttribute
    2. {
    3.     public ArrayDefaultValueAttribute(int[] value) : base((object)value) { }
    4.     public ArrayDefaultValueAttribute(float[] value) : base((object)value) { }
    5. }
    6.  
    7. [ArrayDefaultValue(new int[2] { 2, 5 })]
    8. public int[] Variable { get; set; }
    and this seems to solve the problem. Thanks again!
     
    Last edited: Jan 12, 2021
    JoshPeterson likes this.