NullRef exception in wrong spot

0
0

Is there any reason a NullReference exception would be thrown far away from where the error actually occured?  Is there a way to fix it?

I’m calling a delete-from-database method in a Button click event, in the click event it then refreshes the Listview.  The null reference is because there is no matching ID to delete, but it is thrown on the lvTrucks.Items.Clear() line.

Just wondering if this is normal, because it makes it hard to debug.  The exception happened somewhere else entirely.

 

Thanks

Andrew

 

 

System.NullReferenceException
HResult=0x80004003
Message=Object reference not set to an instance of an object.
Source=Wisej.Framework
StackTrace:
at Wisej.Web.ListView.OnItemsRemoved(ListViewItem[] items)

See attached

Attachment
  • You must to post comments
0
0

I tried this

 

lvTrucks.SelectedIndex = -1;
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear();

lvTrucks.Items.EndUpdate();

In many variations but cannot reproduce.

What Wisej build?

Are you using VirtualMode?

Can you reproduce in an isolated sample?

Do you some some async/task operation on the listview?

 

  • Andrew Niese
    setting .SelectedIndex to -1 is the workaround. You have to remove that to reproduce it. If you still can’t, I can add you to a repo. It’s pretty basic. No Virtual mode or async happening.
  • Luca (ITG)
    Yep, thanks! We just release a hot fix for another regression :(
  • Andrew Niese
    Is that Yep you found it, or yep you want to see the repo? :)
  • Luca (ITG)
    Found, fixed, and looking at why it escaped the tests.
  • Frank (ITG)
    Fixed in Dev Build. 2.2.38. Regards, Frank
  • You must to post comments
0
0

The bug only throws when you try to call .Clear() with a ListViewItem selected. I can workaround the bug by de-selecting any selected items before calling .BeginUpdate(); and .Items.Clear();

this definitely appears to be a WiseJ bug!

 

lvTrucks.SelectedIndex = -1;
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear();

  • You must to post comments
0
0

Actually, I can generate this error just by calling   TrucksToListView();  a second time from another button click.    It seems if you select a ListViewItem, and you call the refresh code, it randomly fails.

private void TrucksToListView()
{
lvTrucks.BeginUpdate();
lvTrucks.Items.Clear(); //throws error here
for (int i = 0; i < Trucks.Count; i++)
{
Trucks tk = Trucks[i];
ListViewItem li = new ListViewItem();
li.Text = tk.id.ToString();
li.SubItems.Add(tk.type);
li.SubItems.Add(tk.truckNumber);
li.SubItems.Add(tk.inspectionDueDate.ToString());
li.SubItems.Add(tk.inService);

li.Tag = tk.id; //tag is storing the truck ID.

lvTrucks.Items.Add(li);//add the listitem
}
lvTrucks.EndUpdate();
}

  • You must to post comments
Showing 3 results
Your Answer

Please first to submit.