2001: unsafe method exception

[Obfuscation(Feature = "ultra", Exclude = false)]
public unsafe class UnsafeClass
{
    
    public void UnsafeMethod()
    {
        int* ptr = stackalloc int[1];
        *ptr = 42;
        Console.WriteLine("Unsafe method: " + *ptr);
    }
}

Type “System.IntPtr” cannot cast to “System.Int32&”

Below works fine.

public static unsafe void unsafe2()
        {
            Console.WriteLine("Unsafe2");
            int* pointer = stackalloc int[10];
            for (int i = 0; i < 10; i++)
            {
                pointer[i] = i;
            }
            Console.WriteLine($"Stackalloc result: {pointer[5]}");
        }
 private static unsafe int PerformUnsafeOperation(int[] numbers)
        {
            fixed (int* pointer = numbers)
            {
                int sum = 0;
                for (int i = 0; i < numbers.Length; i++)
                {
                    sum += pointer[i];
                }
                return sum;
            }
        }

This one gets NullPointerException

P.S.
This Exception can’t decode Stack trace using map file.
Only the “main” function’s name decoded

Fixed in the 2023 build except this:

public unsafe class UnsafeClass
{
    
    public void UnsafeMethod()
    {
        int* ptr = stackalloc int[1];
        *ptr = 42;
        Console.WriteLine("Unsafe method: " + *ptr);
    }
}