I had the same issue in VS2022 and I managed it to work disabling debug optimization checkbox in the project properties->Build->General: