Click to See Complete Forum and Search --> : strange NullReferenceException
dannystommen
June 16th, 2010, 02:27 AM
Hi guys,
I get some strange NullReferenceException once in a while (see screenshot). The 'TempDatasource' variable is a Dictionary<int, DataItem>, where DataItem is a custom class. The variable 'rn' is an integer.
I'm using VS2010 & .Net 4. Could this be a bug in the framework?
boudino
June 17th, 2010, 06:26 AM
What is the stack? Haven't you defined you own GetHashCode(), Equals() method in DataItem?
dannystommen
June 17th, 2010, 07:13 AM
The DataItem class is a simple class that only contains some int and string properties. No methods defined. I created this class because I need to bind some data to a gridview from different sources.
boudino
June 18th, 2010, 01:58 AM
Can you post the code?
dannystommen
June 18th, 2010, 02:09 AM
(only the relevant code)
public partial class cpm : System.Web.UI.Page {
private bool completed = false;
private Dictionary<int, DataItem> TempDatasource = new Dictionary<int, DataItem>();
class DataItem {
public int rn_number { get; set; }
public int imps { get; set; }
public string name { get; set; }
public DateTime enddate { get; set; }
}
protected void Page_Load(object sender, EventArgs e) {
Report report = new Report();
report.Completed += Process;
report.Run(); //runs the report async
while (!completed)
Thread.Sleep(50);
//now the report is ready, load some data from the local database and set the name and enddata
//...
gridview1.DataSource = TempDatasource.Values;
gridview1.DataBind();
}
void Process(API.ExecuteReportCompletedEventArgs<API.Reporting.Network> e) {
if (e.error != null) {
//log error
}
else {
foreach (var item in e.result.Data) {
int rn;
if (RN.IsValid(item.line_item, item.line_item_id, out rn)) {
if (!TempDatasource.ContainsKey(rn)) {
TempDatasource.Add(rn, new DataItem());
TempDatasource[rn].rn_number = rn;
}
TempDatasource[rn].imps += item.imps;
}
}
}
completed = true;
}
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.