簡體   English   中英

XElement.Load .NET CF Windows CE 5.0 中的本機異常

[英]XElement.Load native exception in .NET CF Windows CE 5.0

我在 Windows CE 5.0 上使用 C#.NET CF 3.5,並且還有另一個問題。 在我的應用程序中,我使用“XElement”class 從/向 XML 文件加載/保存一些數據作為我的配置。 我有名為“加載”和“保存”的 static 方法,它們獲取要加載和保存的鍵和字符串值。 它工作正常。 但是當我調用我的 Save 方法超過 4 次時,我得到一個本機錯誤。 似乎必須處置以前加載的 XElement 文檔或類似的東西。 但如何? 或者怎么了? 我的保存方法:

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);
}

感謝 Waleed 和 Henk Holterman,根據我的經驗,由於 memory 在使用非托管代碼和本機 DLL 時泄漏的某些原因,會出現本機錯誤代碼為 0x00000005 的本機異常。 我在許多其他方面遇到了同樣的錯誤。 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托管代碼!

希望這很有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM