Sunday, 15 August 2010

sorting - TargetInvocationException Being Thrown c# -



sorting - TargetInvocationException Being Thrown c# -

i have routine called upon background worker completing. below;

private void batterylistfetchbackgroundworkerrunworkercompleter(object sender, runworkercompletedeventargs e) { this.cursor = cursors.default; var sortedlist = this.currentbatteries.values.orderby(g => g, new batterynamecomparer()); //breaks here this.batterybindingsource.datasource = sortedlist; if (this.batterylistbox.items.count > 0) { this.batterylistbox.setselected(0, true); } this.viewschedulebutton.enabled = true; this.viewdefaultschedulebutton.enabled = true; this.vieweditschedulelimits.enabled = true; }

the line it's breaking @ is;

this.batterybindingsource.datasource = sortedlist;

the exception null reference exception , occurs when setting info source

the code batterynamecomparer

public class batterynamecomparer : icomparer<battery> { /// <summary> /// compares ddsmgroup /// </summary> /// <param name="a">first value comparison</param> /// <param name="b">second value comparison</param> /// <returns>an integer indicating compare result</returns> public int compare(battery a, battery b) { int aid = int.parse(a.devicename.substring(batteryoverviewcontrol.batteryprefixsubstring.length)); int bid = int.parse(b.devicename.substring(batteryoverviewcontrol.batteryprefixsubstring.length)); homecoming aid.compareto(bid); } }

whenever see targetinvocationexception, should inspect innerexception property find exception thrown.

http://msdn.microsoft.com/en-us/library/system.exception.innerexception(v=vs.110).aspx

simply put, targetinvocationexception tells exception thrown within sort of invocation context - cross thread operation or phone call via reflection.

c# sorting exception nullreferenceexception targetinvocationexception

No comments:

Post a Comment