Thank you @shingo for providing the link that explains the issue!
According to one of the commenters:
The root cause of the HttpListenerException (32) on ports 50000–50059 is that HTTP.sys (the kernel-mode listener underpinning HttpListener) cannot bind these ports because Windows has them reserved as part of its dynamic (ephemeral) port range or via excluded port ranges on the local machine. By default on modern Windows (Vista and later), TCP ephemeral ports span 49152 to 65535, and attempting to bind within that range without first excluding or reconfiguring it leads to “Error 32: The process cannot access the file because it is being used by another process.”
To fix this you can adjust the dynamic port range:
netsh int ipv4 set dynamic tcp start=60000 num=5536
Or exclude specific ports:
netsh int ipv4 add excludedportrange protocol=tcp startport=50000 numberofports=10
See link for details.