Bug Report T294186
Visible to All Users

ArgumentOutOfRangeException occurs when the PivotGrid.RestoreLayoutFromStream method is used between BeginUpdate/EndUpdate methods

created 9 years ago

I have recently upgraded our application from 14.1.6 to 15.1.7.

I have turned on the Conditional Formatting and was trying it out.
I changed the OptionsLayout Store FormatRules to true.

I then edited the grid to show some of the conditional formatting options and saved the xml to our server.

In my source code, when I refresh the query I save the current xml to a stream

System.IO.Stream compstream = new System.IO.MemoryStream();
                        xdoc.Save(compstream);
                        if (compstream.Position > 0)
                        { compstream.Position = 0; }

Then after loading the data to the datasource I reload the xml
                            pivotSearchResults.BeginUpdate();
                            pivotSearchResults.RestoreLayoutFromStream(compstream);
                            pivotSearchResults.EndUpdate();

This is also performed immediately after I do an initial load of the XML from the server and execute the query, and this is when the error occurs.

When executing RestoreLayoutFromStream I get an ArgumentOutOfRangeException.
Note this only occurs for layouts that I saved with the StoreFormatRules option turned on and that I have configured conditional formatting for.  We have a lot of previously stored layouts that were created in 14.1.6 and they load fine.

I have attached the xml that gives me the error.(this should be the same xml that is in the stream as immediately after I Save to the Stream , I performed a SaveLayoutToXml to create the file.

We have similar logic in our application for the xtragrid, and that works without a hitch.

As I cannot debug your methods, please let me know what in the xml is causing the error, and how I can work around this problem.

Show previous comments (5)
DevExpress Support Team 9 years ago

    >>commenting out BeginUpdate/EndUpdate seemed to fix the problem.
    I am happy to hear that you have resolved this issue.

    >> I assume you probably want to make your code more robust by properly checking the bounds
    The cause of this exception is that PivotGrid tries to apply settings to fields that are not yet created due to the locked updating. Checking collection bounds will not solve the problem. That's why we recommend you avoid using the BeginUpdate/EndUpdate methods in combination with the RestoreLayoutFrom~ methods.

    JB JB
    Jeffrey Bombard 9 years ago

      Well, apparently you are doing something different now that is causing the error, because this code worked fine in 14.1.6.  Also DevExpress.XtraPivotGrid.Data.PivotFieldItemCollection.get_Item(Int32 index) is where the error appears to occur because the "index" is greater than the collection size.  That can be checked and handled, preferably to fix the problem but if nothing else just to provide better error handling.  Also loading from an xml file doesn't seem to generate the error, so not sure what you are doing differently just because it is a stream.  Regardless, I find it extremely hard to believe you cannot make the code more robust(as there are very few situations where this is true), whether or not you are interested in doing so is up to you.

      DevExpress Support Team 9 years ago

        Hi Jeffrey,
        I have managed to reproduce this issue with the provided sample project and passed this ticket to our developers for further research.  We will update this ticket once we have any results.

        Answers approved by DevExpress Support

        created 9 years ago

        We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

        Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.