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
835
Save/Load of Grid layout results in NullRef Exception
posted

Hi,

I have some code that saves and loads a grid layout exactly as described by Mike in the post here (http://es.infragistics.com/community/forums/p/26520/97683.aspx#97683). On upgrade from 9.1 to 12.1, we're seeing some issues when someone is trying to load a layout that they had saved back during 9.1 (I can't create a sample for repro yet unfortunately). The error that we're seeing is

   at Infragistics.Win.UltraWinGrid.UltraGridLayout.LoadHelper(Stream stream, PropertyCategories propertyCategories, IFormatter formatter)

   at Infragistics.Win.UltraWinGrid.UltraGridLayout.LoadFromXml(Stream stream, PropertyCategories propertyCategories)

   at Infragistics.Win.UltraWinGrid.UltraGridLayout.LoadFromXml(Stream stream)

I've seen a few posts mentioning this stack, but it usually had something to do with old references that weren't updated (not an issue for us) or some misuse of encoding into the stream. The encoding is something we don't do, although I must confess I did notice we were previously using ascii encoding but only on load of the layout, not save...just to be clear, this is what we were doing before:

On save:

MemoryStream memStream = new MemoryStream();
mGrid.DisplayLayout.SaveAsXml(memStream);
if (memStream != null)
{
memStream.Position = 0;
StreamReader reader = new StreamReader(memStream);

<do something with the xml data here>

}

On load:

{

MemoryStream memStream = new MemoryStream(ASCIIEncoding.ASCII.GetBytes(pLayoutXML));
mGrid.DisplayLayout.LoadFromXml(memStream);

}

Having seen the above-linked post, I changed the loading code to match what Mike recommended, but alas that didn't seem to help (and given that the original 9.1 layout was saved without an encoder, I think that is proof that encoding isn't the issue)

On taking a look at the source code for UltraGridLayout, I'm seeing the contents of LoadHelper, but it isn't clear to me what exactly is null...but it is probably the result of formatter.Deserialize( stream ) which means that there is probably something wrong with the stream, right?

Any help would be appreciated. Thanks!

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    I don't see anything wrong with how you were saving the layout. Clearly the way in which you were loading it could have been a problem. But you say you are no longer using the same method to load the layout, so I'm not sure why that's relevant to the discussion. Can you post the code showing how you re loading the layout now? It looks like you are not loading the layout from the stream, but instead you are loading it from some form of XML stored in memory, so my guess is that you may still have an encoding problem.

    Why are you doing anything at all with the XML? Why not just save the data into the stream and load it back in from the same stream? Or better yet, if you are saving and loading in memory, why not just use CopyFrom and store the layout in an UltraGridLayout variable?

    Beyond that, I can't guess why this exception is occurring.

Children