Error inexplicable

21/12/2005 - 10:46 por Marcos Caballero | Informe spam
Buenas a todos, estoy migrando una aplicación realizada en VB .net 2003 a Vb
2005, uso el express, y a la hora de empezar el debug y de depurar los
errores que tenia, me da el siguiente error:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Copia Logs"
StackTrace:
at Copia_logs.Funciones.LeerRegistro(String QueLeer) in C:\Documents
and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 265
at Copia_logs.Funciones.Chequea_Hora() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 107
at Copia_logs.frm_main.Timer1_Tick(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\Copia logs\Copia logs\frm_control_srv.vb:line 730
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.MessageBox(HandleRef hWnd,
String text, String caption, Int32 type)
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner,
String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon,
MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean
showHelp)
at System.Windows.Forms.MessageBox.Show(String text, String caption,
MessageBoxButtons buttons, MessageBoxIcon icon)
at Copia_logs.Funciones.comprueba_event() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 80
at Copia_logs.frm_main.frm_main_Load(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\Copia logs\Copia logs\frm_control_srv.vb:line 704
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at Copia_logs.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


En la versión anterior funcionaba sin problemas, no entiendo porque aquí no
funciona. Deciros que lo estoy realizando en otra máquina, no donde tengo
instalado el 2003.

Os adjunto el codigo donde se detiene el debbuger.

Public Function LeerRegistro(ByVal QueLeer As String) As String
Dim Reg As Microsoft.Win32.RegistryKey
Dim Result As String
Select Case QueLeer.ToUpper.Trim
Case "HORA"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("HoraInicio") <== Aqui da el error.
Reg.Close()
Return Result
Case "SCTLOGS"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("RutaLogs")
Reg.Close()
Return Result
Case "SCBLOGS"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("RutaLogs2")
Reg.Close()
Return Result
Case "NODO1"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("NODO1")
Reg.Close()
Return Result
Case "NODO2"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("NODO2")
Reg.Close()
Return Result
Case "ISA2004"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("ISA2004")
Reg.Close()
Return Result
Case Else
Return 0
End Select

End Function


Gracias por la ayuda.
 

Leer las respuestas

#1 A.Poblacion
21/12/2005 - 11:22 | Informe spam
"Marcos Caballero" wrote in
message news:
Buenas a todos, estoy migrando una aplicación realizada en VB .net 2003 a
Vb
2005, uso el express, y a la hora de empezar el debug y de depurar los
errores que tenia, me da el siguiente error:

System.NullReferenceException was unhandled
Message="Object reference not set to an instance of an object."
Source="Copia Logs"
StackTrace:
at Copia_logs.Funciones.LeerRegistro(String QueLeer) in C:\Documents
and Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 265
at Copia_logs.Funciones.Chequea_Hora() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 107
at Copia_logs.frm_main.Timer1_Tick(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\Copia logs\Copia logs\frm_control_srv.vb:line 730
at System.Windows.Forms.Timer.OnTick(EventArgs e)
at System.Windows.Forms.Timer.TimerNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.MessageBox(HandleRef hWnd,
String text, String caption, Int32 type)
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner,
String text, String caption, MessageBoxButtons buttons, MessageBoxIcon
icon,
MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean
showHelp)
at System.Windows.Forms.MessageBox.Show(String text, String caption,
MessageBoxButtons buttons, MessageBoxIcon icon)
at Copia_logs.Funciones.comprueba_event() in C:\Documents and
Settings\Administrator\My Documents\Visual Studio 2005\Projects\Copia
logs\Copia logs\funciones.vb:line 80
at Copia_logs.frm_main.frm_main_Load(Object sender, EventArgs e) in
C:\Documents and Settings\Administrator\My Documents\Visual Studio
2005\Projects\Copia logs\Copia logs\frm_control_srv.vb:line 704
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean
fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.ContainerControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at
System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&
m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd,
Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd,
Int32 nCmdShow)
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.set_Visible(Boolean value)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32
reason, ApplicationContext context)
at
System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32
reason,
ApplicationContext context)
at System.Windows.Forms.Application.Run(ApplicationContext context)
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at
Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[]
commandLine)
at Copia_logs.My.MyApplication.Main(String[] Args) in
17d14f5c-a337-4978-8281-53493378c1071.vb:line 81
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[]
args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence
assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


En la versión anterior funcionaba sin problemas, no entiendo porque aquí
no
funciona. Deciros que lo estoy realizando en otra máquina, no donde tengo
instalado el 2003.

Os adjunto el codigo donde se detiene el debbuger.

Public Function LeerRegistro(ByVal QueLeer As String) As String
Dim Reg As Microsoft.Win32.RegistryKey
Dim Result As String
Select Case QueLeer.ToUpper.Trim
Case "HORA"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("HoraInicio") <== Aqui da el error.
Reg.Close()
Return Result
Case "SCTLOGS"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("RutaLogs")
Reg.Close()
Return Result
Case "SCBLOGS"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("RutaLogs2")
Reg.Close()
Return Result
Case "NODO1"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("NODO1")
Reg.Close()
Return Result
Case "NODO2"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("NODO2")
Reg.Close()
Return Result
Case "ISA2004"
Reg = LocalMachine.OpenSubKey("Software\ProcesoCopiaLogs",
False)
Result = Reg.GetValue("ISA2004")
Reg.Close()
Return Result
Case Else
Return 0
End Select

End Function






El error que te da (NullReferenceException) se produce cuando tratas de
llamar a un método de un objeto y el objeto vale "Nothing". En tu caso, te
da al llamar a Reg.GetValue, lo cual quiere decir que en ese momento "Reg"
vale Nothing (verifícalo con el debugger). La variable Reg la has cargado en
la linea anterior con Reg=LocalMachine.OpenSubKey(...). El motivo más
probable de que te devuelva Nothing es que la clave en cuestión no exista en
el Registro de WIndows. En cambio, en el otro ordenador en que sí que te
funciona, probablemente sí que debe existir esa clave en el registro.

Preguntas similares