0
votes

I am trying to save an object (Class1) as string in a cell value. My issue is that from time to time I have a ComException:

HRESULT: 0x8007000E (E_OUTOFMEMORY)

(It is kind of random but I have not identified any particular pattern yet) when I write the value into a cell. Any ideas will be welcome

For illustration purposes: Let Class1 be the class to be converted to an Xml string. (Notice that I removed the xml declaration at the start of the string to avoid having the preamble present- non printable character)
<Class1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ElementID> HL690375</ElementID>
</Class1>"

Class1 myClass = new Class1();
this class is converted to a string s. s= ConvertObjectToXmlString(myClass);
then s is assigned to a cell
Range r = Application.ActiveCell;
r.Value2 = s;

Note: (1) If the string is too big, I limit it to 32000 chars and split the string in chunks of 32000 chars and save the chunks in multiple cells.
(2) I do not to quote the string before adding to a cell. Do I need to? If so how it can be done?
(3) All object contents are English.
(4) C# code sample will be great but VB.net code is OK.

1
Log the contents of the string on each use. When exception occurs, compare logged value to previous values and see if any pattern emerges.AMissico

1 Answers

0
votes

It may be that your created string (s) contains 'illegal' characters at times... like a $ which Excel is trying to convert into another cell location... It may not be EXACTLY a $ but you get the idea.