I am working C#.NET CF 3.5 on Windows CE 5.0 , and have another problem.
in my app i load/save some data from/to a XML file as my config by using ‘XElement’ class.
i have static methods named ‘Load’ and ‘Save’ that get a key and a string value to load and save. it works fine. but when i call the my Save method more than 4 times i get a native error. it seems that the previously loaded XElement docs must be disposed or something like that. but how? or what’s the matter?
my Save method :
private static void Save(string keyName,string Value)
{
string strConfigFilePath = CheckConfigFileExistence(); // checks file existence and returns only the file name
XElement xeDoc = XElement.Load(strConfigFilePath); // HERE! throws a native exception at 4th method call!
XElement xeAppSettings = xeDoc.Element("appSettings"); // find 'appSettings' section
XElement xKey = xeAppSettings.Elements("add").Where(el => el.Attribute("key").Value == keyName).FirstOrDefault(); // find the desired key
xKey.Attribute("value").Value = Value;
xeDoc.Save(strConfigFilePath);
}
Thanks to Waleed and Henk Holterman ,
Depend on my experience , the native exception with native error code 0x00000005 occures for some reasons of memory leaks in working with unmanaged codes and native DLLs. i faced same error with in many other points. in my project, i called some native DLL functions writing to input/output parameters like byte[] and *BYTE and etc. i think any fault and indelicacy in writing to memory by unmanaged code and C++ codes causes that exceptions later in irrelevant points in managed code!
hope this be useful.