Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > Index was outside of bounds of the array error in VSTO Excel application

Answered Index was outside of bounds of the array error in VSTO Excel application

  • Wednesday, February 07, 2007 12:37 AM
     
     
     

    We are encountering an error in an application when we are trying to import XML data

    Te application is an Excel smart document. The error is being reproduced all the time.

    The sheet data is being populated but with an exception that returns "Index was outside of bounds of the array" error

    Microsoft.Office.Interop.Excel.XlXmlImportResult xl =new Microsoft.Office.Interop.Excel.XlXmlImportResult();

    xl = Globals.ThisWorkbook.XmlImportXml(XMLDataset, out xmlMap1, true, range1);

     

    Thank you,

    Dmitry

Answers

  • Monday, February 19, 2007 3:41 PM
    Moderator
     
     Answered

    Hi Dmitry

    And which code statement is generating the error? The first or the second?

    Since xlXmlImportResult is an enumeration, you can't create it as an object using the new keyword. Generally, Office object models don't allow you to use new to create objects within the application interface. And when an Office application returns an Enum value, what you'll really get back is an Integer value corresponding to the enum's underlying value. So try something more like this:

    int xmlImportResult;
    xmlImportResult = Globals.ThisWorkbook.XmlImportXml(XMLDataset, out xmlMap1, true, range1);