A Repasky

A Repasky

  • NA
  • 231
  • 182.8k

Instance problem.

Apr 12 2013 7:44 PM


I copied some code online and everything looked well until I ran it and got an error on the return line below.  Does anyone have an idea what I should do?
arep


public
static Cell GetCell(WorksheetPart workSheetPart, string cellAddress)
{
return workSheetPart.Worksheet.Descendants<Cell>().SingleOrDefault(c => cellAddress.Equals(c.CellReference));
}

 System.NullReferenceException: Object reference not set to an instance of an object.
  at DetailReport.GenData.<>c__DisplayClass1.<GetCell>b__0(Cell c) in c:\CLI\CS\DetailReport\GenData.cs:line 122
  at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
  at DetailReport.GenData.GetCell(WorksheetPart workSheetPart, String cellAddress) in c:\CLI\CS\DetailReport\GenData.cs:line 122
  at DetailReport.Program.ExtractData(String product, String reporttitle, String whereClause, String lob) in c:\CLI\CS\DetailReport\Program.cs:line 168
  at DetailReport.Program.GenDetailReports() in c:\CLI\CS\DetailReport\Program.cs:line 114
  at DetailReport.Program.Main(String[] args) in c:\CLI\CS\DetailReport\Program.cs:line 36


It is called this way:


Cell cell7 = GenData.GetCell(wsp1, celladdress);

Answers (5)