I think I solved my own problem, but I'm not sure why it worked.
I noticed the project had a reference to Microsoft.Jet.OLEDB.4.0 which I think is 32 bit. There also was some old code that was no longer called using this reference. When I removed that code, and removed the reference, then I could build and deploy the project with VS2022 and it worked.
Why would this prevent the website from running on the server? And why weren't there any error messages?