Hi all,I have written an application that makes use of the DisplayLayouts' SaveAsXml() and LoadFromXml() functions.Everything works fine until I bind a DataTable (manually constructed) that has column names containing special characters like äöü etc.The LoadFromXml() call fails giving a System.Xml.XmlException: "Invalid character in the given encoding. Line xyz, position xyz."
Is there a way to deal with such column names or anything I can do to make the function work with such DisplayLayouts?Renaming the columns unfortunately isn't an option.
thanks in advance and have a great dayAndy
Hello Andy,
Could you please let me know of your exact version so I can test that in a sample, I am not able to reproduce it right now with 11.2.2050 and 12.1.2008.
Hi Boris,thank you for your quick response, it is very much appreciated.
We are using 11.2.20112.1010, the unsigned, version free assemblies.
Here is a copy of the calls:
using (MemoryStream ms = new MemoryStream(Encoding.Default.GetBytes(_displayLayoutXml))) { try { grdResults.DisplayLayout.LoadFromXml(ms); } catch (Exception ex) { Debug.Print(ex.ToString()); } }
using (MemoryStream ms = new MemoryStream()) { grdResults.DisplayLayout.SaveAsXml(ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { gridLayoutXml = sr.ReadToEnd(); } } cheersAndy
using (MemoryStream ms = new MemoryStream()) { grdResults.DisplayLayout.SaveAsXml(ms); ms.Position = 0; using (StreamReader sr = new StreamReader(ms)) { gridLayoutXml = sr.ReadToEnd(); } }
cheersAndy
Thank you for the attachment. So if you are not able to wrap this part into a sample, I suggest that we work on my sample. Please take a look and make the necessary modifications in order to reproduce this behavior.
Hi Boris,thanks a lot for the sample.I modified it so it reproduces the problem.I now get exactly the same error as in my main application using the DataSet you created.
let me know if you have any questions and best regardscheersAndy
Thank you for the sample provided. I downloaded and ran it but I do not get any exception or error, or a failure of some kind. Could you describe what exactly is the problem here? When I click on the button and execute Test1() method, the application just continues to run as it is the moment before. I got a little confused about this issue here, so a few details would be needed.
Hi Boris,hmmm... in Form1.cs line 109 there is a Debug.Print statement that, in my case, prints the following exception to the console:
System.Xml.XmlException: Invalid character in the given encoding. Line 260, position 18.
at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.Throw(String res, String arg)
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.ParseElementContent()
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XmlTextReader.Read()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.ParseXml()
at System.Runtime.Serialization.Formatters.Soap.SoapParser.Run()
at System.Runtime.Serialization.Formatters.Soap.ObjectReader.Deserialize(HeaderHandler handler, ISerParser serParser)
at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream, HeaderHandler handler)
at System.Runtime.Serialization.Formatters.Soap.SoapFormatter.Deserialize(Stream serializationStream)
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)
at WindowsFormsApplication2.Form1.Test1() in D:\tmp\WindowsFormsApplication2\WindowsFormsApplication2\Form1.cs:line 105
I could reproduce this behavior on three machines right now, are you sure you don't get this exception. If not this is indeed pretty strange...
I indeed will research this further and for now am attaching a video from the execution of this sample(without changing any assemblies or something else).
Please take a look, I might be missing something, hope you could guide me if I am.
Hi Mike,
I hope you are doing good.
Thanks a lot for this suggestion... it totally makes sense.I'll stick to this approach :)
cheers and thanks for this suggestionAndy
Hi,
Using an Encoder to convert the stream into a string is a really bad idea. The whole point of an Encoder is to manipulate the stream and coerce it into a string of a particular encoding type. Modifying the stream in this way is basically just asking for it to be damaged.
If you want to convert the stream into a string, a better way to do it would be to use the StreamReader class - and then use a StreamWriter to get it back into a stream.
There's a similar discussion thread where I posted some sample code here:
Convert String to Stream correctly for DisplayLayout.Load() - Infragistics Community
Hello,
Thank you for your feedback, please let me know if you have any question or if something comes up.
Hi Boris,after carefully investigating the video there was one thing that made me look closer.Actually everything you did was exactly what I did, but while comparing the outputs I found a slight difference. I had a decoder fallback operation in my output, you didn't.
So I changedEncoding.Default.GetBytes(displayLayoutAsString)
toEncoding.UTF32.GetBytes(displayLayoutAsString)
That seems to do the trick...
I will check with my main application but I am optimistic that this will fix the problem.
I am deeply sorry for troubling you with this problem, but I appreciated you help very much.That again was a perfect sample for great support! Keep it up :)
So thank you very much Boris and have a great weekend,best regardsAndy