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

290
Views
Misterio System.Object.GetType() NullReferenceException

Experimentamos un bloqueo en nuestro programa que ahora no podemos reproducir. Estoy tratando de ingresar un código para evitar que vuelva a suceder, pero estoy confundido con el seguimiento de la pila.

 System.NullReferenceException: Object reference not set to an instance of an object. at System.Object.GetType() at Project.ViewModel.MainVM.<CreateCommands>b__8(Object a) at System.Windows.Controls.Button.OnClick()

-- He reducido el seguimiento de la pila, ya que solo entra en una carga de código del sistema que solo tiene que ver con el botón en el que se hace clic. --

Logré deducir que apunta a mi delegado anónimo en la línea 8 de mi método CreateCommands.

 this.sectionCommand = new DelegateCommand(a => { this.OnSectionParameterChanged((Sections)a); }, p => this.IsSectionCommandExecutable);

He visto una publicación similar aquí, pero el OP llamaba explícitamente a GetType. Supongo que las llamadas de reparto obtienen tipo, pero sin poder reproducir el problema, no puedo ver qué es nulo.

Entonces, mi pregunta es: para que este seguimiento de pila cause una referencia nula, ¿la variable 'a' es el objeto nulo? (así que escribiría algo como)

 if (a != null) { this.OnSectionParameterChanged((Sections)a); }

¿O la conversión de 'a' a 'secciones' está causando un objeto nulo? (así que debería escribir algo como)

 if (a is Sections) { this.OnSectionParameterChanged((Sections)a); }

Como se solicita aquí es OnSectionParameterChanged

 private void OnSectionParameterChanged(Sections parameter) { this.SelectedSection = parameter; this.RaisePropertyChanged(() => this.SelectedSection); this.LoadSettingsPanel(); }

además de eso, llama a LoadSettingsPanel

 private void LoadSettingsPanel() { if (sectionVMs == null) return; // Get section SectionViewModel = sectionVMs.SingleOrDefault(s.SectionName == SelectedSection); this.IsSelectedSectionEnabled = this.Config.GetIsSectionEnabled(this.SelectedSection); this.RaisePropertyChanged(() => this.IsSelectedSectionEnabled); // Set advanced AdvancedViewModel = this.SectionViewModel; if (AdvancedViewModel != null) HasAdvanced = AdvancedViewModel.HasAdvanced; }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

El problema que había descrito en realidad no era el problema real. Leí en un sitio diferente que la parte < CreateCommands >b__8 del seguimiento de la pila significaba que el problema estaba en la línea 8 del método CreateCommands . Esto se alineó exactamente con un delegado anónimo y pude ver cómo coincidía con el comportamiento en el informe de errores.

De hecho, encontré la solución a mi problema usando IL Dasm (que se puede encontrar en

\Archivos de programa (x86)\Microsoft SDKs\Windows\v7.0A\Bin

y abrió el EXE que se ejecutó y encontró lo que .net pensó que b__8 realmente era. Este resultó ser otro delegado anónimo que estaba llamando explícitamente a .GetType() , por lo que el problema fue realmente fácil una vez que descubrí qué significaba realmente b__8 .

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!