IL2CPP error when building for IOS

When building our game for IOS we are getting an error related to IL2CPP. I haven’t been able to find a solution in the existing topics.

Unity 5.6.0f3
Scripting backend: IL2CPP
Api Compatibility Level: .NET 2.0 or .NET 2.0 subset (no difference)

I tried changing the scripting backend to Mono2x but then I also get an error that I can’t find a solution for (see error below this error).

Any suggestions please?

IL2CPP

Failed running /Applications/Unity/Unity.app/Contents/il2cpp/build/il2cpp.exe --convert-to-cpp --emit-null-checks --enable-array-bounds-check --development-mode --map-file-parser=“/Applications/Unity/Unity.app/Contents/Tools/MapFileParser/MapFileParser” --assembly=“/Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed/Assembly-CSharp-firstpass.dll” --assembly=“/Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll” --assembly=“/Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed/UnityEngine.UI.dll” --assembly=“/Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed/UnityEngine.dll” --generatedcppdir=“/Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/il2cppOutput/il2cppOutput”

stdout:
IL2CPP error for type ‘System.Byte’ in /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Byte.cs:173
Additional information: Index was outside the bounds of the array.
il2cpp.exe didn’t catch exception: System.IndexOutOfRangeException: Index was outside the bounds of the array.
at Unity.IL2CPP.Common.CFG.ControlFlowGraphBuilder.MarkBlockEnds (System.Collections.Generic.IList1[T] instructions) [0x00008] in <e06de6cfd5be4fe0a14ebcb03867166a>:0 at Unity.IL2CPP.Common.CFG.ControlFlowGraphBuilder.DelimitBlocks () [0x00027] in <e06de6cfd5be4fe0a14ebcb03867166a>:0 at Unity.IL2CPP.Common.CFG.ControlFlowGraphBuilder.CreateGraph () [0x00001] in <e06de6cfd5be4fe0a14ebcb03867166a>:0 at Unity.IL2CPP.Common.CFG.ControlFlowGraph.Create (Mono.Cecil.MethodDefinition method) [0x0002a] in <e06de6cfd5be4fe0a14ebcb03867166a>:0 at Unity.IL2CPP.MethodBodyWriter..ctor (Unity.IL2CPP.CppCodeWriter writer, Mono.Cecil.MethodReference methodReference, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, Unity.IL2CPP.IRuntimeMetadataAccess metadataAccess, Unity.IL2CPP.Metadata.VTableBuilder vTableBuilder, Unity.IL2CPP.MethodBodyWriterDebugOptions options) [0x00096] in <ac25355623854e1087bde44b673dbfca>:0 at Unity.IL2CPP.MethodBodyWriter..ctor (Unity.IL2CPP.CppCodeWriter writer, Mono.Cecil.MethodReference methodReference, Unity.IL2CPP.ILPreProcessor.TypeResolver typeResolver, Unity.IL2CPP.IRuntimeMetadataAccess metadataAccess, Unity.IL2CPP.Metadata.VTableBuilder vTableBuilder) [0x0000d] in <ac25355623854e1087bde44b673dbfca>:0 at Unity.IL2CPP.MethodWriter.WriteMethodBody (Mono.Cecil.MethodReference method, Unity.IL2CPP.CppCodeWriter methodBodyWriter, Unity.IL2CPP.IRuntimeMetadataAccess metadataAccess) [0x00054] in <ac25355623854e1087bde44b673dbfca>:0 at Unity.IL2CPP.MethodWriter+<WriteMethodDefinition>c__AnonStorey0.<>m__0 (Unity.IL2CPP.CppCodeWriter bodyWriter, Unity.IL2CPP.MetadataUsage metadataUsage, Unity.IL2CPP.MethodUsage methodUsage) [0x00040] in <ac25355623854e1087bde44b673dbfca>:0 at Unity.IL2CPP.MethodWriter.WriteMethodWithMetadataInitialization (Unity.IL2CPP.CppCodeWriter writer, System.String methodSignature, System.String methodFullName, System.Action3[T1,T2,T3] writeMethodBody, System.String uniqueIdentifier) [0x00045] in :0
at Unity.IL2CPP.MethodWriter.WriteMethodDefinition (Mono.Cecil.MethodReference method, Unity.IL2CPP.IMethodCollector methodCollector, Unity.IL2CPP.Metadata.IMethodVerifier methodVerifier) [0x00208] in :0
at Unity.IL2CPP.MethodWriter.WriteMethodDefinitions (Unity.IL2CPP.IMethodCollector methodCollector, Unity.IL2CPP.Metadata.IMethodVerifier methodVerifier) [0x00083] in :0
at Unity.IL2CPP.SourceWriter.WriteMethodSourceFiles (NiceIO.NPath outputDirectory, System.String fileName, System.Collections.Generic.IEnumerable`1[T] typeList, Unity.IL2CPP.IMethodCollector methodCollector, Unity.IL2CPP.Metadata.IMethodVerifier methodVerifier, Unity.IL2CPP.IInteropDataCollector interopDataCollector, Unity.IL2CPP.Symbols.SymbolsCollector symbolsCollector, System.Boolean writeMarshalingDefinitions) [0x00176] in :0
at Unity.IL2CPP.SourceWriter.Write (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.GenericsCollection.ReadOnlyInflatedCollectionCollector allGenerics, NiceIO.NPath outputDir, Mono.Cecil.TypeDefinition[ ] typeList, Unity.IL2CPP.AttributeCollection attributeCollection, Unity.IL2CPP.MethodCollector methodCollector, Unity.IL2CPP.Metadata.IMethodVerifier methodVerifier, Unity.IL2CPP.IInteropDataCollector interopDataCollector, Unity.IL2CPP.Metadata.IMetadataCollection metadataCollection, Unity.IL2CPP.Symbols.SymbolsCollector symbolsCollector) [0x000b5] in :0
at Unity.IL2CPP.AssemblyConverter.Convert (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.GenericsCollection.ReadOnlyInflatedCollectionCollector allGenerics, Unity.IL2CPP.AttributeCollection attributeCollection, Unity.IL2CPP.MethodCollector methodCollector, Unity.IL2CPP.Metadata.IMethodVerifier methodVerifier, Unity.IL2CPP.IInteropDataCollector interopDataCollector, Unity.IL2CPP.Metadata.IMetadataCollection metadataCollection, Unity.IL2CPP.Symbols.SymbolsCollector symbolsCollector) [0x0002f] in :0
at Unity.IL2CPP.AssemblyConverter.Apply () [0x000c9] in :0
at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies (NiceIO.NPath[ ] assemblies, NiceIO.NPath outputDir, NiceIO.NPath dataFolder, NiceIO.NPath symbolsFolder) [0x00011] in :0

Mono2x

Cross compilation job Assembly-CSharp.dll failed.
UnityEngine.UnityException: Failed AOT cross compiler: /Applications/Unity/PlaybackEngines/iOSSupport/Tools/OSX/mono-xcompiler-wrapper.sh --aot=full,asmonly,nodebug,static,outfile=“Assembly-CSharp.dll.s” “Assembly-CSharp.dll” current dir : /Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed
result file exists: False. Timed out: False

stdout:
Mono Ahead of Time compiler - compiling assembly /Users/Jasper/Documents/src/PuzzlePlatform/PuzzleGame/Temp/StagingArea/Data/Managed/Assembly-CSharp.dll
* Assertion at loader.c:2354, condition `loc’ not met

stderr:

at UnityEditor.MonoProcessUtility.RunMonoProcess (System.Diagnostics.Process process, System.String name, System.String resultingFile) [0x000e2] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/MonoAssemblyStripping.cs:112
at UnityEditor.MonoCrossCompile.CrossCompileAOT (BuildTarget target, System.String crossCompilerAbsolutePath, System.String assembliesAbsoluteDirectory, CrossCompileOptions crossCompileOptions, System.String input, System.String output, System.String additionalOptions) [0x0034e] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/MonoCrossCompile.cs:318
at UnityEditor.MonoCrossCompile+JobCompileAOT.ThreadPoolCallback (System.Object threadContext) [0x0002c] in /Users/builduser/buildslave/unity/build/Editor/Mono/BuildPipeline/MonoCrossCompile.cs:52
UnityEditor.HostView:OnGUI()

This looks like a bug on the Unity side. Can you submit a bug report and include this project? Also, did this project work with previous versions of Unity?

getting a similar bug, did the issue ever get resolved?

@claytonccollins

No, I don’t believe that we ever got a bug report for this issue. Can you submit one? We would love to be able to correct it.