Skip to content

[borwser][coreCLR] exception in static constructor #122462

@pavelsavara

Description

@pavelsavara

node .\corerun.js /throwcctor.dll

try
{
    Console.WriteLine("Hello, World!");
    Console.WriteLine("BOOM " + XXX.Something);
}
catch (Exception ex)
{
    Console.WriteLine("Caught!");
    Console.WriteLine("Caught : " + ex);
}


class XXX
{
    static XXX()
    {
        Console.WriteLine("Static constructor called.");
        throw new Exception("Exception in static constructor.");
    }

    private static string SomethingField = "Hi";

    public static string Something
    {
        get
        {
            return SomethingField;
        }
    }
}

expected

Hello, World!
Static constructor called.
Caught!
Caught : System.TypeInitializationException: The type initializer for 'XXX' threw an exception.
 ---> System.Exception: Exception in static constructor.
   at XXX..cctor() in D:\samples\throwcctor\Program.cs:line 17
   --- End of inner exception stack trace ---
   at XXX.get_Something() in D:\samples\throwcctor\Program.cs:line 25
   at Program.<Main>$(String[] args) in D:\samples\throwcctor\Program.cs:line 4

actual

Hello, World!
Static constructor called.
Caught!
Caught : System.Exception: Exception in static constructor.
   at XXX..cctor()
   at XXX.get_Something()
   at Program.<Main>$(String[] args)

Assert failure(PID 42 [0x0000002a], Thread: 1 [0x0001]): The 'LastThrownObject' should not be, but is, NULL.
The runtime may have lost track of the type of an exception in flight.
Please get a good stack trace, find the caller of Validate, and file a bug against the owner.

To suppress this assert 'set DOTNET_SuppressLostExceptionTypeAssert=1'
    File: D:/runtime/src/coreclr/vm/clrex.cpp:2125
    Image: /managed

Aborted(native code called abort())

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions