il2cpp stranger compile errors

I just installed Unity 5 and tried to build for IOS for the first time using IL2CPP. I am getting strange errors that don’t make much sense and hopefully somebody can shed some light on this.

IL2CPP error for type ‘TrainingCard’ in Character.cs:385
Additional information: Object reference not set to an instance of an object

First off, this sounds like a runtime issue, but it happens when I try to build

Second TrainingCard is a class that is not mentioned whatsoever in Character.cs, especially not on line 385

There is this checkbox about il2cpp headers. I tried with and without that. Not sure whats it for but it didn’t help the problem.

Thoughts?

There is a 2nd error after this about the same thing, in case anyone needs to see it:

Failed running C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe --copy-level=None --enable-generic-sharing --enable-unity-event-support --emit-null-checks --enable-array-bounds-check --enable-symbol-loading “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\Assembly-CSharp-firstpass.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\Assembly-CSharp.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\Assembly-UnityScript.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\UnityEngine.UI.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\TexturePacker.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\ICSharpCode.SharpZipLib.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\Ionic.Zip.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\StagingArea\Data\Managed\unibill.dll” “C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Temp\il2cppOutput\il2cppOutput”

stdout:
IL2CPP error for type ‘TrainingCard’ in C:\Users\slugger\Documents\code\UnityRPG\RPGEngine\Assets\Scripts\UI\Characters\Character.cs:385
Additional information: Object reference not set to an instance of an object
stderr:

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object

at Unity.IL2CPP.StringLiterals.StringLiteralWriter.Uint16DataInitializerString (System.String stringLiteral) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter+ConstantValue.ConstantValueFor (Mono.Cecil.FieldDefinition field) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter+ConstantValue.DefinitionStatement () [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter.WriteDefinitions (Mono.Cecil.TypeReference type) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldInfoWriter.WriteMetadataDefinitionsFor () [0x00000] in :0

at Unity.IL2CPP.Metadata.Types.TypeInfoWriter.WriteDefinitionFor (Unity.IL2CPP.Metadata.VTableBuilder vTableBuilder, Mono.Cecil.AssemblyDefinition corlib, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteMetadataDefinitionFor (Unity.IL2CPP.CppCodeWriter writer, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, Mono.Cecil.TypeReference type, Unity.IL2CPP.Metadata.Types.TypeInfoWriter typeInfoWriter, Mono.Cecil.AssemblyDefinition mscorlib, System.Collections.Generic.HashSet`1 emptyTypes) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteSource (Unity.IL2CPP.CppCodeWriter writer, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, Mono.Cecil.TypeReference type, System.Collections.Generic.HashSet`1 emptyTypes, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteSourceFiles (System.String outputDirectory, System.String fileName, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, IEnumerable1 typeList, System.Collections.Generic.HashSet1 emptyTypes, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.Write (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, System.String outputDir, Mono.Cecil.TypeDefinition typeList, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.Convert (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics) [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.Apply () [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies (System.String assemblies, System.String outputDir) [0x00000] in :0
[ERROR] FATAL UNHANDLED EXCEPTION: System.NullReferenceException: Object reference not set to an instance of an object

at Unity.IL2CPP.StringLiterals.StringLiteralWriter.Uint16DataInitializerString (System.String stringLiteral) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter+ConstantValue.ConstantValueFor (Mono.Cecil.FieldDefinition field) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter+ConstantValue.DefinitionStatement () [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldDefaultValueWriter.WriteDefinitions (Mono.Cecil.TypeReference type) [0x00000] in :0

at Unity.IL2CPP.Metadata.Fields.FieldInfoWriter.WriteMetadataDefinitionsFor () [0x00000] in :0

at Unity.IL2CPP.Metadata.Types.TypeInfoWriter.WriteDefinitionFor (Unity.IL2CPP.Metadata.VTableBuilder vTableBuilder, Mono.Cecil.AssemblyDefinition corlib, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteMetadataDefinitionFor (Unity.IL2CPP.CppCodeWriter writer, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, Mono.Cecil.TypeReference type, Unity.IL2CPP.Metadata.Types.TypeInfoWriter typeInfoWriter, Mono.Cecil.AssemblyDefinition mscorlib, System.Collections.Generic.HashSet`1 emptyTypes) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteSource (Unity.IL2CPP.CppCodeWriter writer, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, Mono.Cecil.TypeReference type, System.Collections.Generic.HashSet`1 emptyTypes, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.WriteSourceFiles (System.String outputDirectory, System.String fileName, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, IEnumerable1 typeList, System.Collections.Generic.HashSet1 emptyTypes, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.SourceWriter.Write (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics, System.String outputDir, Mono.Cecil.TypeDefinition typeList, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection) [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.Convert (Mono.Cecil.AssemblyDefinition assemblyDefinition, Unity.IL2CPP.StringLiterals.StringLiteralCollection stringLiteralCollection, Unity.IL2CPP.GenericsCollection.InflatedCollection allGenerics) [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.Apply () [0x00000] in :0

at Unity.IL2CPP.AssemblyConverter.ConvertAssemblies (System.String assemblies, System.String outputDir) [0x00000] in :0

UnityEngine.Debug:LogError(Object)
UnityEditorInternal.Runner:RunManagedProgram(String, String, String, CompilerOutputParserBase) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:66)
UnityEditorInternal.IL2CPPBuilder:ConvertPlayerDlltoCpp(ICollection1, String, String) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:404) UnityEditorInternal.IL2CPPBuilder:Run() (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:275) UnityEditorInternal.IL2CPPUtils:RunIl2Cpp(String, String, IIl2CppPlatformProvider, Action1, RuntimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:211)
UnityEditor.HostView:OnGUI()

Exception: C:\Program Files\Unity\Editor\Data\il2cpp/il2cpp.exe did not run properly!
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:68)
UnityEditorInternal.IL2CPPBuilder.ConvertPlayerDlltoCpp (ICollection1 userAssemblies, System.String outputDirectory, System.String workingDirectory) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:404) UnityEditorInternal.IL2CPPBuilder.Run () (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:275) UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, IIl2CppPlatformProvider platformProvider, System.Action1 modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/Il2Cpp/IL2CPPUtils.cs:211)
UnityEditor.iOS.PostProcessiPhonePlayer.PostProcess (UnityEditor.iOS.iOSBuildPostprocessor pp, BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String stagingAreaDataManaged, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry)
UnityEditor.iOS.iOSBuildPostprocessor.PostProcess (BuildPostProcessArgs args)
UnityEditor.PostprocessBuildPlayer.Postprocess (BuildTarget target, System.String installPath, System.String companyName, System.String productName, Int32 width, Int32 height, System.String downloadWebplayerUrl, System.String manualDownloadWebplayerUrl, BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry) (at C:/buildslave/unity/build/Editor/Mono/BuildPipeline/PostprocessBuildPlayer.cs:316)
UnityEditor.HostView:OnGUI()

Try rebuild/update dlls in your project. some dll may compile in lower .Net version. and the IL2CPP compiler do have some very strange compile actions, which could result in errors of the old code.

Ours was solved by a version released 6 months ago. So may be unrelated