Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NativeAOT: type initialization crashing at runtime #72782

Closed
hez2010 opened this issue Jul 25, 2022 · 2 comments
Closed

NativeAOT: type initialization crashing at runtime #72782

hez2010 opened this issue Jul 25, 2022 · 2 comments

Comments

@hez2010
Copy link
Contributor

hez2010 commented Jul 25, 2022

Description

Repro:

var a = TypeUtilities.Get1(2);
var b = TypeUtilities.Get2(2);
var c = TypeUtilities.Get3(2);
var d = TypeUtilities.Get4(2);
Console.WriteLine(a);
Console.WriteLine(b);
Console.WriteLine(c);
Console.WriteLine(d);

static class TypeUtilities
{
    private static readonly int[] Conversions =
    {
        0b101111111111101, // Boolean
        0b100001111111110, // Char
        0b101111111111111, // SByte
        0b101111111111111, // Byte
        0b101111111111111, // Int16
        0b101111111111111, // UInt16
        0b101111111111111, // Int32
        0b101111111111111, // UInt32
        0b101111111111111, // Int64
        0b101111111111111, // UInt64
        0b101111111111101, // Single
        0b101111111111101, // Double
        0b101111111111101, // Decimal
        0b110000000000000, // DateTime
        0b111111111111111, // String
    };

    private static readonly int[] ImplicitConversions =
    {
        0b000000000000001, // Boolean
        0b001110111100010, // Char
        0b001110101010100, // SByte
        0b001111111111000, // Byte
        0b001110101010000, // Int16
        0b001111111100000, // UInt16
        0b001110101000000, // Int32
        0b001111110000000, // UInt32
        0b001110100000000, // Int64
        0b001111000000000, // UInt64
        0b000110000000000, // Single
        0b000100000000000, // Double
        0b001000000000000, // Decimal
        0b010000000000000, // DateTime
        0b100000000000000, // String
    };

    private static readonly Type[] InbuiltTypes =
    {
        typeof(Boolean),
        typeof(Char),
        typeof(SByte),
        typeof(Byte),
        typeof(Int16),
        typeof(UInt16),
        typeof(Int32),
        typeof(UInt32),
        typeof(Int64),
        typeof(UInt64),
        typeof(Single),
        typeof(Double),
        typeof(Decimal),
        typeof(DateTime),
        typeof(String),
    };

    private static readonly Type[] NumericTypes =
    {
        typeof(Byte),
        typeof(Decimal),
        typeof(Double),
        typeof(Int16),
        typeof(Int32),
        typeof(Int64),
        typeof(SByte),
        typeof(Single),
        typeof(UInt16),
        typeof(UInt32),
        typeof(UInt64),
    };

    public static Type Get1(int index) => NumericTypes[index];
    public static Type Get2(int index) => InbuiltTypes[index];
    public static int Get3(int index) => ImplicitConversions[index];
    public static int Get4(int index) => Conversions[index];
}

Reproduction Steps

Build with NativeAOT and run.

Expected behavior

No exception should be thrown.

Actual behavior

Unhandled Exception: System.TypeInitializationException: A type initializer threw an exception. To determine which type, inspect the InnerException's StackTrace property.
 ---> System.PlatformNotSupportedException: Operation is not supported on this platform.
   at Internal.Runtime.TypeLoader.ExternalReferencesTable.GetRvaFromIndex(UInt32) + 0x24
   at TypeUtilities..cctor() + 0x9
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0xc6
   --- End of inner exception stack trace ---
   at System.Runtime.CompilerServices.ClassConstructorRunner.EnsureClassConstructorRun(StaticClassConstructionContext*) + 0x167
   at System.Runtime.CompilerServices.ClassConstructorRunner.CheckStaticClassConstructionReturnGCStaticBase(StaticClassConstructionContext*, Object) + 0xd
   at Program.<Main>$(String[]) + 0xc
   at NaotTest!<BaseAddress>+0x1b6113

Regression?

No response

Known Workarounds

No response

Configuration

.NET: latest nightly version
ILC: nightly

Other information

No response

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jul 25, 2022
@jkotas
Copy link
Member

jkotas commented Jul 25, 2022

This is dup of dotnet/roslyn#62864 that was fixed by dotnet/roslyn#62868 .

@jkotas jkotas closed this as completed Jul 25, 2022
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jul 25, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Aug 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants