UnityLinker / build error when IL2CPP backend is selected (Mono.Cecil.GenericParameterConstraint)

Hello,

I found several threads about build errors with IL2CPP backend, but the error mesages are different. I do not have a good understanding what is going wrong during the build process.

Problem: With an new and empty project, regardless of selected platform, all builds with IL2CPP backend fail with the same error message

type “Mono.Cecil.GenericParameterConstraint” in assembly “Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e” could not be loaded

A Standalone / Mono build works. I am posting in the Android forum because it was my first build that failed before I tried other platforms with IL2CPP.

  • Fresh install of Unity 2019.4.17f1 LTS.
  • JDK, Android SDK Tools and Android NDK were installed during installation of 2019.4.17 by Unity Hub.
  • Visual Studio Pro 2019 16.8.2 is installed (including C++ for desktop and game development).
  • Windows SDK 10.0.18362.0 is installed

Exception: C:\Program Files\Unity\Hub\Editor\2019.4.17f1\Editor\Data\il2cpp\build/deploy/net471/UnityLinker.exe did not run properly!

Failed running “C:\Program Files\Unity\Hub\Editor\2019.4.17f1\Editor\Data\il2cpp\build/deploy/net471/UnityLinker.exe” @L:/_PROJECTS/_UNITY/UGS/Temp/StagingArea/assets/bin/Data/Managed/response.rsp

stdout:
Fatal error in Unity CIL Linker
System.TypeLoadException: Der Typ “Mono.Cecil.GenericParameterConstraint” in der Assembly “Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e” konnte nicht geladen werden.
bei Mono.Linker.Steps.MarkStep.MarkGenericParameter(GenericParameter parameter)
bei Mono.Linker.Steps.MarkStep.MarkGenericParameterProvider(IGenericParameterProvider provider)
bei Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
bei Mono.Linker.Steps.MarkStep.MarkField(FieldReference reference)
bei Mono.Linker.Steps.MarkStep.MarkFields(TypeDefinition type, Boolean includeStatic, Boolean markBackingFieldsOnlyIfPropertyMarked)
bei Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
bei Mono.Linker.Steps.MarkStep.MarkType(TypeReference reference)
bei Unity.Linker.Steps.Marking.EngineStrippingMarking.MarkRequiredByNativeMember(ICustomAttributeProvider required)
bei Unity.Linker.Steps.Marking.EngineStrippingMarking.MarkRequiredByNativeMembers(EngineModule module)
bei Unity.Linker.Steps.Marking.EngineStrippingMarking.MarkModule(EngineModule module, Boolean markEngineModule)
bei Unity.Linker.Steps.Marking.EngineStrippingMarking.Initialize()
bei Unity.Linker.Steps.UnityMarkStep.Process(LinkContext context)
bei Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
bei Unity.Linker.UnityPipeline.ProcessStep(LinkContext context, IStep step)
bei Mono.Linker.Pipeline.Process(LinkContext context)
bei Unity.Linker.UnityDriver.Run()
bei Unity.Linker.UnityDriver.RunDriverWithoutErrorHandling()
bei Unity.Linker.UnityDriver.RunDriver()
stderr:

UnityEditorInternal.Runner.RunProgram (UnityEditor.Utils.Program p, System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditorInternal.Runner.RunManagedProgram (System.String exe, System.String args, System.String workingDirectory, UnityEditor.Scripting.Compilers.CompilerOutputParserBase parser, System.Action1[T] setupStartInfo) (at <2f1c602eae0d45c293fff3e3aef759fa>:0) UnityEditorInternal.AssemblyStripper.RunAssemblyLinker (System.Collections.Generic.IEnumerable1[T] args, System.String& out, System.String& err, System.String linkerPath, System.String workingDirectory) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditorInternal.AssemblyStripper.StripAssembliesTo (System.String outputFolder, System.String& output, System.String& error, System.Collections.Generic.IEnumerable1[T] linkXmlFiles, UnityEditorInternal.UnityLinkerRunInformation runInformation) (at <2f1c602eae0d45c293fff3e3aef759fa>:0) UnityEditorInternal.AssemblyStripper.RunAssemblyStripper (UnityEditorInternal.UnityLinkerRunInformation runInformation) (at <2f1c602eae0d45c293fff3e3aef759fa>:0) UnityEditorInternal.AssemblyStripper.StripAssemblies (System.String managedAssemblyFolderPath, UnityEditorInternal.BaseUnityLinkerPlatformProvider unityLinkerPlatformProvider, UnityEditorInternal.IIl2CppPlatformProvider il2cppPlatformProvider, UnityEditor.RuntimeClassRegistry rcr, UnityEditor.ManagedStrippingLevel managedStrippingLevel) (at <2f1c602eae0d45c293fff3e3aef759fa>:0) UnityEditorInternal.IL2CPPBuilder.Run () (at <2f1c602eae0d45c293fff3e3aef759fa>:0) UnityEditorInternal.IL2CPPUtils.RunIl2Cpp (System.String tempFolder, System.String stagingAreaData, UnityEditorInternal.IIl2CppPlatformProvider platformProvider, System.Action1[T] modifyOutputBeforeCompile, UnityEditor.RuntimeClassRegistry runtimeClassRegistry) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEditor.Android.PostProcessor.Tasks.RunIl2Cpp.Execute (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessor.PostProcessRunner.RunAllTasks (UnityEditor.Android.PostProcessor.PostProcessorContext context) (at :0)
UnityEditor.Android.PostProcessAndroidPlayer.PostProcess (UnityEditor.BuildTarget target, System.String stagingAreaData, System.String stagingArea, System.String playerPackage, System.String installPath, System.String companyName, System.String productName, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at :0)
UnityEditor.Android.AndroidBuildPostprocessor.PostProcess (UnityEditor.Modules.BuildPostProcessArgs args, UnityEditor.BuildProperties& outProperties) (at :0)
UnityEditor.PostprocessBuildPlayer.Postprocess (UnityEditor.BuildTargetGroup targetGroup, UnityEditor.BuildTarget target, System.String installPath, System.String companyName, System.String productName, System.Int32 width, System.Int32 height, UnityEditor.BuildOptions options, UnityEditor.RuntimeClassRegistry usedClassRegistry, UnityEditor.Build.Reporting.BuildReport report) (at <2f1c602eae0d45c293fff3e3aef759fa>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr)

This looks like either a bug in the UnityLinker code or some invalid IL code in an assembly in the project. The UnityLinker is used to statically analyze managed code and remove any code that is not used. You can find details about it in our documentation here: Unity - Manual: Managed code stripping

It is required to run when IL2CPP is selected, and is optional for Mono. I think this is why you see this error only with IL2CPP.

I think that you have a few options here.

First, if you can submit this project to us, we would love to get a bug report for this issue so that we can either correct it or improve the error message that occurs so that it provides actionable information.

Second, this seems to occur in the part of the managed linker code related to the “Strip Engine Code” option in the player settings. You may want to try to build with that option disabled - that might work around this problem.

Josh,

thank you for looking into this.

It is a new and empty “3D” project created from Unity Hub. There are no 3rd party assets or code in the project. I even removed the packages in the “Unity Registry” section of the package manager one by one, but no avail. Everything in the project is “built in”.

I disabled the option “Strip Engine Code” in the Android settings, but the problem persists.

I am irritated - if it is a bug I would expect that many people found it before, as it is a standard scenario (latest LTS version, standard Android build and no user code that could cause this). That would also make it easy to reproduce.

The screenshot shows that it is actually a blank project with nothing but the empty scene.

6698389--768703--upload_2021-1-7_13-38-24.png

This is very odd then. It certainly works for an empty project on our end, but I don’t see what might be different on your side. Can you translate the message:

Der Typ “Mono.Cecil.GenericParameterConstraint” in der Assembly “Mono.Cecil, Version=0.10.0.0, Culture=neutral, PublicKeyToken=50cebf1cceb9d05e” konnte nicht geladen werden.

to English for me? Maybe that will provide a clue.

It means “the type “Mono.Cecil.GenericParameterConstraint” in the assembly “Mono.Cecil” could not be loaded”

Thanks for the details. I’ll ask some developers more familiar with the UnityLinker to determine if they have any idea about what might cause this.

Ok, so our best guess now is that this is some issue with code using a C# 8 feature that is not supported in Unity 2019.4. I’m surprised that this happens with an empty project (I don’t see the behavior with the same Unity version on my side). So can you submit a bug report and include this project? There might be something that happened during empty project creation to trigger this issue.

You can find details about how to submit a bug report here: Unity QA: Building quality with passion

Thanks Josh,

I just uploaded a bug report.

1 Like