Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bad assembly when a nested exported type is marked via link.xml
When a nested exported type is marked via link.xml and the declaring type is not marked, cecil will write out an invalid exported type table which will lead to exceptions such as ``` System.ArgumentOutOfRangeException : Specified argument was out of the range of valid values. at Mono.Collections.Generic.Collection`1.get_Item(Int32 index) at Mono.Cecil.MetadataReader.ReadExportedTypes() at Mono.Cecil.ModuleDefinition.<>c.<get_ExportedTypes>b__116_0(ModuleDefinition _, MetadataReader reader) at Mono.Cecil.ModuleDefinition.Read[TItem,TRet](TRet& variable, TItem item, Func`3 read) at Mono.Cecil.ModuleDefinition.get_ExportedTypes() at Mono.Cecil.MetadataResolver.GetType(ModuleDefinition module, TypeReference reference) at Mono.Cecil.MetadataResolver.Resolve(TypeReference type) at Mono.Linker.Tests.TestCasesRunner.TestResolver.TryResolve(TypeReference typeReference) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\test\Trimming.Tests.Shared\TestResolver.cs:line 12 at Mono.Linker.ModuleDefinitionExtensions.ResolveType(ModuleDefinition module, String typeFullName, ITryResolveMetadata resolver) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\src\linker\Linker\ModuleDefinitionExtensions.cs:line 50 at Mono.Linker.TypeNameResolver.<ResolveTypeName>g__GetSimpleTypeFromModule|6_0(TypeName typeName, ModuleDefinition module) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\src\linker\Linker\TypeNameResolver.cs:line 135 at Mono.Linker.TypeNameResolver.ResolveTypeName(AssemblyDefinition originalAssembly, TypeName typeName, List`1 typeResolutionRecords) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\src\linker\Linker\TypeNameResolver.cs:line 101 at Mono.Linker.TypeNameResolver.TryResolveTypeName(AssemblyDefinition assembly, String typeNameString, TypeReference& typeReference, List`1& typeResolutionRecords) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\src\linker\Linker\TypeNameResolver.cs:line 44 at Mono.Linker.Tests.TestCasesRunner.ResultChecker.VerifyLinkingOfOtherAssemblies(AssemblyDefinition original) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\test\Mono.Linker.Tests\TestCasesRunner\ResultChecker.cs:line 320 at Mono.Linker.Tests.TestCasesRunner.ResultChecker.Check(TrimmedTestCaseResult linkResult) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\test\Mono.Linker.Tests\TestCasesRunner\ResultChecker.cs:line 114 at Mono.Linker.Tests.TestCases.All.Run(TestCase testCase) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 305 at Mono.Linker.Tests.TestCases.All.TypeForwardingTests(TestCase testCase) in E:\UnitySrc\dev\unity-runtime-1\src\tools\illink\test\Mono.Linker.Tests\TestCases\TestSuites.cs:line 262 at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr) ``` Or if you were to try and open the linked `Forwarder.dll` without the fix in something like ILSpy, it would crash ILSpy. An easy way to fix this seems to be marking the declaring type.
- Loading branch information