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!
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.
Hey Mike,
You're right that my pointing out the original (perhaps wrong) way of loading the layout isn't totally relevant to the discussion. I was just trying to demonstrate some of the methods I have tried thus far to correct the issue.
The new load layout code looks basically identical to the example you wrote out in that previous forum post (linked at the top of my first post):
MemoryStream memStream = new MemoryStream(); StreamWriter streamWriter = new StreamWriter(memStream); streamWriter.Write(pLayoutXML); streamWriter.Flush();
memStream.Position = 0; mGrid.DisplayLayout.LoadFromXml(memStream);
where pLayoutXML is the xml that we've persisted to disk.The reason we're saving stuff to xml is that this is how we persist our layouts to disk for future use by our product after process shutdown.
It seems weird that the issue only happens after an upgrade in Infragistics versions...don't you think that if it were an encoding issue, it would have been happening before as well? That being said, I do have suspicions there's an encoding problem (even though I try to prevent that from happening per the above discussion) because when I compare a layout that was saved by us (to disk previously before the upgrade) to one that we have now after the upgrade, there are some additional carriage returns in the stream (if I open the old one up in the text editor, there '
' at the end of each line from that saved content). I can't imagine why this would cause formatter.Deserialize to not produce the right results though.