CUDA works on WSL, but not on Windows directly

Hi all,

I am running CUDA on WSL regularly without issues.

Now I tried running the CUDA default template for MSVC 2019, which fails with

cudaSetDevice failed!  Do you have a CUDA-capable GPU installed?

nvidia-smi detects the GPU just fine:

+-----------------------------------------------------------------------------+
| NVIDIA-SMI 465.21       Driver Version: 465.21       CUDA Version: 11.3     |
|-------------------------------+----------------------+----------------------+
| GPU  Name            TCC/WDDM | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  GeForce RTX 2060   WDDM  | 00000000:09:00.0  On |                  N/A |
| 31%   32C    P0    28W / 160W |   1513MiB /  6144MiB |      2%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

Any ideas where I could start to figure out what is going wrong?

Environment:
CUDA Version: 11.2.142,
Driver Version: 465.21
Windows Version: 10.0.21292 Build 21292

EDIT: Some more context on this: cudaSetDevice(0) returns cudaErrorInvalidValue, even though that is not among the reported possible error codes for the function!