Repository: dotnet/runtime
File: src/tests/Interop/TypeMap/TypeMapEntryAssemblyApp.cs (C#)

Code before:
    {
        Console.WriteLine(nameof(Validate_TypeMappingEntryAssembly_ExternalMap));

        // These types should be resolved from TypeMapLib5's type maps
        IReadOnlyDictionary<string, Type> externalMap = TypeMapping.GetOrCreateExternalTypeMapping<AlternateEntryPoint>();

        Assert.Equal(typeof(Lib5Type1), externalMap["lib5_type1"]);
        Assert.Equal(typeof(Lib5Type2), externalMap["lib5_type2"]);

        Assert.True(externalMap.TryGetValue("lib5_type1", out Type? type1));
        Assert.Equal(typeof(Lib5Type1), type1);

        Assert.True(externalMap.TryGetValue("lib5_type2", out Type? type2));
        Assert.Equal(typeof(Lib5Type2), type2);

        Assert.False(externalMap.TryGetValue("nonexistent", out Type? _));
    }

    [Fact]
    public static void Validate_TypeMappingEntryAssembly_ProxyMap()
    {
        Console.WriteLine(nameof(Validate_TypeMappingEntryAssembly_ProxyMap));

        // For NativeAOT, instantiate the type to ensure the mappings are marked
        _ = new Lib5Type1();
        _ = new Lib5Type2();

        // These proxy mappings should be resolved from TypeMapLib5's type maps
        IReadOnlyDictionary<Type, Type> proxyMap = TypeMapping.GetOrCreateProxyTypeMapping<AlternateEntryPoint>();

        Assert.Equal(typeof(Lib5Proxy1), proxyMap[typeof(Lib5Type1)]);
        Assert.Equal(typeof(Lib5Proxy2), proxyMap[typeof(Lib5Type2)]);

        Assert.True(proxyMap.TryGetValue(typeof(Lib5Type1), out Type? proxy1));
        Assert.Equal(typeof(Lib5Proxy1), proxy1);

        Assert.True(proxyMap.TryGetValue(typeof(Lib5Type2), out Type? proxy2));
        Assert.Equal(typeof(Lib5Proxy2), proxy2);

        Assert.False(proxyMap.TryGetValue(typeof(string), out Type? _));
    }
}


Review comment (bug):
This should be rewritten to follow the existing pattern. Any runs that execute ILLinker would also be broken, this is not just for native AOT sake:

https://github.com/dotnet/runtime/blob/891c183b22d023eea7bc4aa57dbc219d54852036/src/tests/Interop/TypeMap/TypeMapApp.cs#L148-L149

Code after:
    {
        Console.WriteLine(nameof(Validate_TypeMappingEntryAssembly_ExternalMap));

        // These types should be resolved from TypeMapLib5's type maps
        IReadOnlyDictionary<string, Type> externalMap = TypeMapping.GetOrCreateExternalTypeMapping<AlternateEntryPoint>();

        Assert.Equal(typeof(Lib5Type1), externalMap["lib5_type1"]);
        Assert.Equal(typeof(Lib5Type2), externalMap["lib5_type2"]);

        Assert.True(externalMap.TryGetValue("lib5_type1", out Type? type1));
        Assert.Equal(typeof(Lib5Type1), type1);

        Assert.True(externalMap.TryGetValue("lib5_type2", out Type? type2));
        Assert.Equal(typeof(Lib5Type2), type2);

        Assert.False(externalMap.TryGetValue("nonexistent", out Type? _));
    }

    [Fact]
    public static void Validate_TypeMappingEntryAssembly_ProxyMap()
    {
        Console.WriteLine(nameof(Validate_TypeMappingEntryAssembly_ProxyMap));

        // These proxy mappings should be resolved from TypeMapLib5's type maps
        IReadOnlyDictionary<Type, Type> proxyMap = TypeMapping.GetOrCreateProxyTypeMapping<AlternateEntryPoint>();

        Assert.Equal(typeof(Lib5Proxy1), proxyMap[new Lib5Type1().GetType()]);
        Assert.Equal(typeof(Lib5Proxy2), proxyMap[new Lib5Type2().GetType()]);

        Assert.False(proxyMap.TryGetValue(typeof(string), out Type? _));
    }
}