Finally fixed it. I found that the state and code verifier had to be longer than 28 characters, when I went to 56 characters it worked.
So replace the two occurrences of 28 with 56 above and the code given will work as a simple solution to end to end okta pkce authentication in raw ASP.NET
Another example of end to end auth in pure javascript was posted today here: Authenticate with pure restful API calls - #3 by islwyn10