Hard bug to spot for sure. It's due to a difference between C# and Java. C#'s Stack.ElementAt() is not the same thing as Java's Stack.elementAt()/Stack.get(). They're actually reversed. Also, ElementAt is a Linq extension method and not a default method like in Java. See the below code/output:
import java.util.Stack;
Stack<Integer> stack = new Stack<Integer>();
stack.push(1);
stack.push(2);
stack.push(3);
System.out.println(stack.elementAt(0));
Output: 1
using System;
using System.Collections.Generic;
using System.Linq;
Stack<int> stack = new();
stack.Push(1);
stack.Push(2);
stack.Push(3);
Console.WriteLine(stack.ElementAt(0));
Output: 3