Null Reference Exception RRS feed

  • Question

  • I have another issue from a related app: The code executes correctly on my home PC, but not on my office PC.  Please see the last three lines below (2 comment lines and 1 code line). The code line produces a "null reference" exception on my office PC, but not on my home PC.

    =============== Code ====================

     // Map Styles  
                MessageBox.Show("Beginning", "Caption");
                using (WordprocessingDocument doc = WordprocessingDocument.Open(documentPath, true))
                    // Get all paragraphs
                    IEnumerable<DocumentFormat.OpenXml.Wordprocessing.Paragraph> paragraphs =

                    // For each paragraph...
                    foreach (DocumentFormat.OpenXml.Wordprocessing.Paragraph para in paragraphs)
                        // The following line of code works on my home PC (with Word 2007 & Visual Studio 2010),
                        // but yields a 'null ref' exception on my office PC (with Word 2010 & Visual Studio 2010):
                        string styleID = para.ParagraphProperties.ParagraphStyleId.Val;  // NULL REF EXCEPTION ON OFFICE PC

    Thursday, September 11, 2014 3:34 PM

All replies