Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
¿Por qué obtengo System.NullReferenceException en mi script C# mientras funciona mi ejecutable del mismo código?

Tengo el siguiente script .csx:

 #r "C:\Windows\Microsoft.NET\assembly\GAC_MSIL\System.Management\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Management.dll" using System.Management; ManagementClass cls = new ManagementClass("\\\\.\\root\\default:StdRegProv");

Cuando ejecuto esto usando el dotnet script este error:

 System.NullReferenceException: Object reference not set to an instance of an object. at System.Management.MTAHelper.IsNoContextMTA() at System.Management.MTAHelper.CreateInMTA(Type type) at System.Management.ManagementPath.CreateWbemPath(String path) at System.Management.ManagementPath..ctor(String path) at System.Management.ManagementClass..ctor(String path) at Submission#0.<<Initialize>>d__0.MoveNext() in <..path..>\script.csx:line 3 --- End of stack trace from previous location --- at Dotnet.Script.Core.ScriptRunner.Execute[TReturn](String dllPath, IEnumerable`1 commandLineArgs) in <...path...>\Temp\tmpBFB\Dotnet.Script.Core\ScriptRunner.cs:line 110

Si compilo el siguiente código en Visual Studio, todo funciona bien:

 using System.Management; class Script { static void Main() { ManagementClass cls = new ManagementClass("\\\\.\\root\\default:StdRegProv"); } }

Por qué ? ¿Cómo puedo hacer que mi script .csx funcione?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El script dotnet se ejecuta en .NET Core y no creo que WMI funcione en .NET Core, ya que necesita interoperabilidad COM. Mira esto .

Además, el dll de tiempo de ejecución global para .NET CORE no está en GAC sino en un almacén de paquetes de tiempo de ejecución .

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!