Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
400
Workbook.Load throws NullReferenceException when Named reference refers to Named Range
posted

Hello,

Just thought I would let you know that Workbook.Load will throw a NullReferenceException when the following occurs.  Granted the spreadsheet probably did not have to define this named reference this way but it does show a bug with the order in which named references are calculated along with named ranges in those references.

Our spreadsheet has a Named reference with

Name             Referes To

bdBondsLs    =OFFSET(dbDescFirst,1,0,COUNTA(BondData!$A:$A)-1,1)

dbDescFirst   =BondData!$A$1

The bug was reproduced using 11.1.20111.2111 and 12.1.20121.2024 of Infragistics2.Documents.Excel.

Using the source code I was able to locate where the exception was thrown.  It is thrown when ResumeCalculations attempts to calculate the bdBondsLs named reference and the value for dbDescFirst is NULL at this point because it has not been calculated yet.  The code I will refer to below is from 12.1.

ResumeCalculations calls SetAndCompileFormula for bdBondLs.  Display value for Formula argument is:

newExcelFormula = Formula: =OFFSET(,1,0,COUNTA(BondData!$A:$A)-1,1)

Notice that the first argument to OFFSET shows as empty instead of dbDescFirst.  The first token in the formula appears to be a NameToken but the Token property is NameR, the TokenClass property is Reference, and the Name property is null.  I do not know when the first argument to OFFSET in the formula loaded is a NameToken with name NULL but the spreadsheet has name dbDescFirst.  When ConvertToken is called to get the value for the token it tries to get the namedReference by calling workbook.GetWorkbookScopedNamedItem but it passes NULL as the argument since the tokens name is NULL instead of dbDescFirst.  The GetWorkbookScopedNamedItem calls TryGetValue(null, out namedItem) which throws the NullReferenceException.

So that is the bug, somehow when the workbook is loaded it is not properly creating the named reference token for dbDescFirst in the =OFFSET formula in the bdBondLs named reference.

Sounds like an issue with named references which in turn reference other named references.

  • 20872
    Offline posted

    Hello emarkunger,

    We are still following this forum thread. Have you been able to verify if would be possible for you to provide us a small sample application where you have experiencing the very same behavior? If that is not possible could you please try to post here the stack trace of the issue that you are experiencing so we will have at least a pointer where this issue comes from, and we will be glad to continue the investigation of this behavior.

    If you have any other issues or questions please do not hesitate to let us know.

  • 20872
    Offline posted

    Hello emarkunger,

    Thank you very much for your efforts. We will definitely look into this behavior. Would you be able to provide us a small sample application where you have experiencing the very same behavior, so we will investigate further what is the real cause of this behavior and what could be done in order to resolve this behavior.

    If you have any other questions please feel free to let us know.