I am running the following code - which takes the data from an XML file and updates a SQL Mobile table - it seems to consistenly throw a native exception error (ExceptionCode: 0xc0000005)
Here is the code:
#region
DataRefreshFromXML public void RefreshDataFromXML(){
if (File.Exists(appPath + @"\data\HandheldInventory.xml")) try{
DataSet ds = new DataSet();ds.ReadXml(appPath +
@"\data\HandheldInventory.xml"); if (ds.Tables.Count > 0){
using (SqlCeConnection cn = GetConnection()){
SqlCeDataAdapter da;da =
new SqlCeDataAdapter("SELECT * FROM MobileInventory", cn); SqlCeCommandBuilder cb;cb =
new SqlCeCommandBuilder(da);da.InsertCommand = cb.GetInsertCommand();
da.InsertCommand.Connection = cn;
String sSQLCommand = "DELETE FROM MobileInventory;"; SqlCeCommand cmdAdder = new SqlCeCommand(sSQLCommand, cn);cmdAdder.ExecuteNonQuery();
DataSet ds2 = new DataSet();da.Fill(ds2);
ds.Merge(ds2,
false, MissingSchemaAction.Add);da.Update(ds.Tables[
"Table"]);}
}
}
catch (SqlCeException ex){
MessageBox.Show("Could not refresh HandheldInventory Data: " +ex.Message +
")!", "RIO Data Load Error", MessageBoxButtons.OKCancel, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);}
else MessageBox.Show("The HandheldInventory.xml is missing, please re-run the desktop synchronization application", "RIO Data Merger Error");}

Native Exception Error - 0xc0000005
Jaime Stuardo
This line does not do any native interop (pretty much the only source of native exceptions) and been used very heavily so bug in the framework's runtime is unlikely (thought not impossible).
It might be your code it doing some interop prior to this point and it blows later on as memory been consumed on that line. Good thing to try is to create new empty application and do just that line in it.
Another possible reason would be corrupted installation. Try hard resetting your device and reinstalling NETCF.
I’m assuming you’re using NETCF V2 since you’ve mention SQL Mobile, is that right
Akamba
Great, please go ahead and step through your code until problem would show up.
That would tell us which line is to blame.
robinjam
Which line leads to that exception
Kamii47
Managed debugger won't break on native exception. But you can step through the code until problem actually happens.
Just put a breakpoint at the start suspected function (and I’m not convinced code you’ve provided is to blame) and step through until you see native exception.
Lanceli
Ok - it looks like it is blowing up on the following line:
ds.ReadXml(appPath +
@"\data\HandheldInventory.xml");Malmer
Swati Handa
OK - here is the code that is causing the memory leak - not certain what is going wrong here - the purpose of it is to anchor data to a menuitem and then assign child menu items based upon the parentID - any help would be greatly appreciated!!!!
private
void LoadAccounts(){
SqlCeDataReader dr = null; SqlCeDataReader dr2 = null; try{
dr = data.LoadAccountNamesAndIDs();
while (dr.Read()){
MyMenuItem miAccountName = new MyMenuItem();miAccountName.Text = dr[
"AccountName"].ToString();miAccountName.Tag = dr[
"AccountID"].ToString();miAccount.MenuItems.Add(miAccountName);
dr2 = data.LoadAccountLocations(miAccountName.Tag);
if (dr2.Read()){
MyMenuItem mainthreadNode = new MyMenuItem();mainthreadNode.Text =
"All Items";mainthreadNode.Tag = dr[
"AccountID"].ToString();miAccountName.MenuItems.Add(mainthreadNode);
mainthreadNode.Click +=
new EventHandler(mi_Click); while (dr2.Read()){
MyMenuItem threadNode = new MyMenuItem();threadNode.Text = dr2[
"LocationName"].ToString();threadNode.Tag = dr[
"AccountID"].ToString();miAccountName.MenuItems.Add(threadNode);
threadNode.Click +=
new EventHandler(mi_Click);}
}
else{
miAccountName.Enabled =
false;}
}
}
catch (Exception ex){
MessageBox.Show("Could not load Account Names: " +ex.Message +
")!", "RIO Data Load Error");}
finally{
if (dr != null){
dr.Dispose();
dr.Close();
if (dr2 != null){
dr2.Dispose();
dr2.Close();
}
}
}
}
Space Support
I have detected possible problem areas in my c++ code.Although I have put try catch block but I don't think that catches the problem.Please let me know is my way of catching Access Violation error is correct or not
I have used following type of try/catch
try{
// my code
}
catch(...)
{
//code for logging the error [although I have put this type of try catch in lot of places but can't get any error logged]
}
SteveFortner
I seem to be getting the same Native Exception code. But can't seem to think where it is coming from. When I use the following line of code to try and determine how much memory is being used the memory consumption is fine.
MessageBox.Show(GC.GetTotalMemory(false).ToString());
Is it possible that this only tells you want your application is actually consuming, and not if there are any memory leaks
Thanks
Tryst
ChanKaiShi
That is the problem - even in debug, it does not break at the line throwing the error - the app just fails with the error:
ExceptionCode: 0xc0000005
ExceptionAddress: 0x01246e34
Reading: 0x00000005
EmekaAwagu
stratos13
The below represents the code that I have which is calling the first set of code - the error only occurs within the application after I click the cutton that calls the below - approx 3-5 seconds after I click on the button to intiate the data update method:
private void miRefresh_Click(object sender, EventArgs e){
dlgRes =
MessageBox.Show("Refreshing RIO data may take several minutes. Continue ", "Confirm RIO Data Refresh", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dlgRes == DialogResult.Yes){
try{
Cursor.Current = Cursors.WaitCursor;data.RefreshDataFromXML();
Cursor.Current = Cursors.Default;}
catch (Exception ex){
MessageBox.Show("An error occured while importing the data from the desktop to the mobile device: " +ex.Message.ToString(),
"RIO Data Import Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation, MessageBoxDefaultButton.Button1);}
}
}
Derek Comingore
I am synchronizing some pocket outlook data.{I am using P/Invokes , unsafe code, etc}
If anybody have find the solution then please let me know
Mr Geoff
That exception is a very generic AV (access violation) and it probably has nothing to do with memory leak which is different issues.
AV happens if application is trying to access something in memory which does not belong to it. In managed application it generally caused by incorrect P/Invoke or incorrect unsafe code usage.
If you using native DLL (e.g. bar code scanner API) it can come from that native DLL due to incorrect parameters been passed or due to bug in it. In many cases AV manifests itself in completely irrelevant part of the application because memory or stack have been corrupted at some point by other portion of the code. It’s usually very hard to track.
I would recommend isolation strategy: identify potentially problematic code areas (e.g. P/Invokes, 3rd party libraries with P/Invokes, unsafe code, etc. ), exclude them and see if problem is gone. Return that code gradually till it returns.