Skip to content

[area-Tools-ILLink]: TypeMap entries for array types result in build failure when PublishTrimmed #126177

@manodasanW

Description

@manodasanW

Description

If we PublishTrimmed an app with a TypeMap entry with the trim target as an array, it causes the below error. PublishAot and no trimming seems to work fine.

Reproduction Steps

using ConsoleApp36;
using System.Runtime.InteropServices;

// [assembly: TypeMap<TestTypeMap>("Type1", typeof(SameTargetType), typeof(DifferentTrimTarget1))]
[assembly: TypeMap<TestTypeMap>("Type3", typeof(SameTargetType), typeof(DifferentTrimTarget1[]))]

namespace ConsoleApp36
{
    class TestTypeMap { }


    internal class Program
    {
        static void Main(string[] args)
        {
            DifferentTrimTarget1[] target1 = [new DifferentTrimTarget1()];
            Console.WriteLine(target1);

            // Console.WriteLine("value: " + System.Runtime.InteropServices.TypeMapping.GetOrCreateExternalTypeMapping<TestTypeMap>()["Type1"]);
            Console.WriteLine("value: " + System.Runtime.InteropServices.TypeMapping.GetOrCreateExternalTypeMapping<TestTypeMap>()["Type3"]);
        }
    }


    class DifferentTrimTarget1
    {
    }

    class SameTargetType
    {
    }
}

Expected behavior

Doesn't result in build failure similar to AOT publishing

Actual behavior

2>ILLink(0,0): Error IL1012: IL Trimmer has encountered an unexpected error. Please report the issue at https://aka.ms/report-illink
2>Fatal error in IL Linker
2>Unhandled exception. System.NotSupportedException: TypeDefinition cannot be resolved from 'Mono.Cecil.ArrayType' type
2>   at Mono.Linker.LinkContext.Resolve(TypeReference typeReference)
2>   at Mono.Linker.TypeMapHandler.RecordTypeMapEntry(ValueTuple`2 attr, TypeReference group, TypeReference dependencySource, Dictionary`2 pendingDependencySourceMarking, HashSet`1 seenTypeGroups, Dictionary`2 pendingTypeMapGroupMarking)
2>   at Mono.Linker.TypeMapHandler.AddExternalTypeMapEntry(TypeReference group, ValueTuple`2 attr)
2>   at Mono.Linker.TypeMapHandler.TypeMapResolver.Resolve(LinkContext context, TypeMapHandler manager)
2>   at Mono.Linker.TypeMapHandler.Initialize(LinkContext context, MarkStep markStep, AssemblyDefinition entryPointAssembly)
2>   at Mono.Linker.Steps.MarkStep.Initialize()
2>   at Mono.Linker.Steps.MarkStep.Process(LinkContext context)
2>   at Mono.Linker.Pipeline.ProcessStep(LinkContext context, IStep step)
2>   at Mono.Linker.Pipeline.Process(LinkContext context)
2>   at Mono.Linker.Driver.Run(ILogger customLogger)
2>   at Mono.Linker.Driver.Main(String[] args)
2>The command exited with code -532462766.
2>Output Property: _ILLinkExitCode=-532462766

Regression?

No response

Known Workarounds

No response

Configuration

.NET 10

Other information

No response

Metadata

Metadata

Labels

area-Tools-ILLink.NET linker development as well as trimming analyzerspartner-impactThis issue impacts a partner who needs to be kept updated

Type

No type
No fields configured for issues without a type.

Projects

Status

No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions