System.Management throws PlatformNotSupportedException under hosted CLR on Windows — breaks Hardware.Info, DeviceId.Windows.Wmi, etc.
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 45/100
Línea de trabajo
Comienza con el nad-repro.zip adjunto, especialmente con repro.js, probe y probe-console, y ejecuta los casos native console y node-api-dotnet en Windows. Lee el comportamiento del hosting en torno al aislamiento de AssemblyLoadContext y compáralo con la limitación referenciada de System.Management. Se considera terminado cuando se determine si la capa de hosting puede solucionar el fallo; si no, documenta la limitación en la README.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Summary
Any NuGet package that uses System.Management (WMI) fails with PlatformNotSupportedException when loaded through node-api-dotnet
on Windows, even though the same package works fine from a native .NET console on the same machine.
Confirmed against node-api-dotnet@0.9.21 pinned to both /net8.0 and /net10.0. WSL2 (Linux runtime, no WMI path) works normally.
Repro
Attached zip (nad-repro.zip, ~4 KB, 8 source files, no node_modules / DLLs):
nad-repro/
├── package.json node-api-dotnet@0.9.21 only
├── repro.js 18 lines of Node
├── probe/ Class library; only ref is Hardware.Info 101.0.0
└── probe-console/ net8.0 console exe — control case
Steps:
npm install
dotnet publish probe -c Release -f net8.0 -o native --no-self-contained
Baseline — works:
dotnet run --project probe-console -c Release -f net8.0
cpuCount=1 coreCount=16 error=(none)
node-api-dotnet — fails:
node repro.js
{
"cpuCount": 0,
"coreCount": 0,
"error": "PlatformNotSupportedException: System.Management currently is only supported for Windows desktop applications."
}
Stack:
System.Management.ManagementOptions..ctor()
System.Management.EnumerationOptions..ctor()
Hardware.Info.Windows.HardwareInfoRetrieval..ctor(Nullable)
Hardware.Info.HardwareInfo..ctor(Boolean, Nullable)
Environment
- Windows 11 23H2 (also Windows 10)
- .NET 10.0.202 SDK installed (project targets net8.0)
- node-api-dotnet 0.9.21
- Hardware.Info 101.0.0
- Node 22.x
What works / doesn't
| Scenario | Result |
|---|---|
| Native .NET 8 console, same Probe.dll | ✓ Works |
| node-api-dotnet/net8.0 on Windows | ✗ PlatformNotSupportedException |
| node-api-dotnet/net10.0 on Windows (with .NET 10 runtime installed) | ✗ Same exception |
| node-api-dotnet/net8.0 inside WSL2 Ubuntu (Linux runtime, no WMI) | ✓ Works |
Root cause (probably)
Likely a downstream symptom of dotnet/runtime#110604 (https://github.com/dotnet/runtime/issues/110604) — System.Management
rejects initialization in AssemblyLoadContext-isolated load scenarios. node-api-dotnet's hosting model puts the CLR into exactly
such a context. The workaround that issue proposes (explicit pre-load via LoadFromAssemblyPath) does not help here — pre-loading
System.Management.dll through dotnet.load() before the consumer DLL produces the same exception.
Impact
Every NuGet package that relies on System.Management on Windows is unusable via node-api-dotnet:
- Hardware.Info (CPU/motherboard/etc enumeration)
- DeviceId.Windows.Wmi
- Most machine-fingerprinting / license-binding libraries
The failure is silent: the exception happens inside a constructor that's typically wrapped in try/catch by consumers, so callers
receive zero-filled or empty results and produce wrong outputs (in our case: a downstream consumer reads Cpucount == 0 and concludes 'no CPUs detected,' even though the machine has 16 physical cores.).
Is this fixable at the node-api-dotnet hosting layer, or is the
PlatformNotSupportedException strictly an upstream System.Management
limitation that node-api-dotnet has no leverage over?
If it is upstream-only, would it be worth documenting this as a known
limitation in the README so the next person doesn't have to discover it
the hard way? Happy to contribute the docs PR.
Reproducer is attached as nad-repro.zip — runs in under a minute on any
Windows machine with .NET 10 SDK + Node 22 installed.
- Lenguaje dominante
- C#
- Estrellas
- 783
- Forks
- 80
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de microsoft/node-api-dotnet
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 88/100
microsoft/node-api-dotnet#484 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
microsoft/node-api-dotnet#481 ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
microsoft/node-api-dotnet#486 · 1 comentario ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
microsoft/node-api-dotnet#483 · 1 comentario · 1 reacción ·
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
microsoft/node-api-dotnet#475 · 1 comentario ·
Todos los issues de microsoft/node-api-dotnet
Issues similares
-
type/automation type/tech-debt
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
-
t/bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
ci-failure-cause test-failure
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
-
area:auth FE mvp P3
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
klasolsson81/jobbliggaren#1788 ·