Bonjour,

Je dois modifier un programme fait par une autre personne et j'ai une erreur que je n'arrive pas à débuger.

L'erreur est System.NullReferenceException was unhandled

Elle apparait quand j'utilise la ligne suivante :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
OF_Selected.get_CPs().Find(Function(x) x.C_ref = "X" & ref Or x.C_ref = "Z" & ref).C_ref
Cette ligne liste des composants (get_CPs()) et avec le Find est sensée me donner accès à un composant (X & ref ou Z & ref).

Si je boucle sur l'ensemble des éléments fournis par get_CPs(), j'ai bien tous les composants, dont le composant recherché.
Quand j'ajoute le find, il plante avec cette erreur.

NB : J'utilise cette même fonction ailleurs dans le programme et elle fonctionne parfaitement.

Comment réussir à débuger l'erreur ?

Voici le détail de l'erreur :

System.NullReferenceException was unhandled
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=Component Airlock Datamatrix
StackTrace:
at CAD.Main.set_all_values_MultiOF(String ref, String& lot1, String& lot2, String& lot3, String& lot4, String& lot5, String& lot6, String& dlu) in G:\@Informatique\Projets\VisualStudio\Component Airlock Datamatrix\Component Airlock Datamatrix\Main.vb:line 275
at CAD.Form2.Btn_OK_Click(Object sender, EventArgs e) in G:\@Informatique\Projets\VisualStudio\Component Airlock Datamatrix\Component Airlock Datamatrix\Form2.vb:line 32
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
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.RunDialog(Form form)
at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
at System.Windows.Forms.Form.ShowDialog()
at CAD.Form2.ShowDialog(CP& Composant) in G:\@Informatique\Projets\VisualStudio\Component Airlock Datamatrix\Component Airlock Datamatrix\Form2.vb:line 17
at CAD.Form1.CP_Grid_CellDoubleClick(Object sender, DataGridViewCellEventArgs e) in G:\@Informatique\Projets\VisualStudio\Component Airlock Datamatrix\Component Airlock Datamatrix\Form1.vb:line 253
at System.Windows.Forms.DataGridView.OnCellDoubleClick(DataGridViewCellEventArgs e)
at System.Windows.Forms.DataGridView.OnDoubleClick(EventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.DataGridView.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.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()
at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)
at CAD.My.MyApplication.Main(String[] Args) in :line 81
at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.AppDomain.nExecuteAssembly(RuntimeAssembly assembly, String[] args)
at System.Runtime.Hosting.ManifestRunner.Run(Boolean checkAptModel)
at System.Runtime.Hosting.ManifestRunner.ExecuteAsAssembly()
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext, String[] activationCustomData)
at System.Runtime.Hosting.ApplicationActivator.CreateInstance(ActivationContext activationContext)
at System.Activator.CreateInstance(ActivationContext activationContext)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssemblyDebugInZone()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
InnerException: