Click here to Skip to main content
15,888,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
application stopped working when i open in debugging mode using C#
one image are

What I have tried:

C#
private void Export()
{ 
 SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            saveDialog.FilterIndex = 2;

            if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                xlWorkBook.SaveAs(saveDialog.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                StripStatusLabel.Visible = true;
                StripStatusLabel.Image = Image.FromFile(@"\\90.0.0.8\d\Nouman's Development\SizaPayRoll For Backup\backup\SizaPayRoll\icons\images (3).jpg");
                StripStatusLabel.ForeColor = Color.Green;
                StripStatusLabel.Text = "Increment export to excel successfully...";
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }
            else if (saveDialog.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
            {

            }
}
 private void releaseObject(object obj)
        {
            try
            {
                System.Runtime.InteropServices.Marshal.ReleaseComObject(obj);
                obj = null;
            }
            catch (Exception ex)
            {
                obj = null;
                MessageBox.Show("Exception Occured while releasing object " + ex.ToString());
            }
            finally
            {
                GC.Collect();
            }
        }
Posted
Updated 20-Dec-16 0:27am
Comments
Richard MacCutchan 20-Dec-16 4:59am    
Sorry but we cannot guess where it stopped.
OriginalGriff 20-Dec-16 5:03am    
So put a breakpoint at the top of each method, and step through until it "stops".
Then tell us what it was showing just before.
Remember we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.
Siza International 20-Dec-16 5:08am    
ok thanks, but i want share an image,but there is no option available
Siza International 20-Dec-16 5:11am    
After stop the application my application are showing that error
An unhandled exception of type 'System.AccessViolationException' occurred in System.Windows.Forms.dll

Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
OriginalGriff 20-Dec-16 5:24am    
So use the debugger and find out where it was immediately before the problem showed up.
Probably, what you have done is passed bad data, or a wrong value to Excel - but we can't help you work out which without you gathering information as we can't run your code: we don't have any access to your data!

And posting an image is not allowed - a picture of a crash message tells un nothing useful anyway!

1 solution

I only can suppose ... but I think you should change your code like this :
C#
private void Export()
{ 
 SaveFileDialog saveDialog = new SaveFileDialog();
            saveDialog.Filter = "Excel files (*.xlsx)|*.xlsx|All files (*.*)|*.*";
            saveDialog.FilterIndex = 2;
            DialogResult myResult = saveDialog.ShowDialog ;  // <- Changes here !!!

            if (myResult == System.Windows.Forms.DialogResult.OK)  // <- Changes here !!!
            {
                xlWorkBook.SaveAs(saveDialog.FileName, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);
                StripStatusLabel.Visible = true;
                StripStatusLabel.Image = Image.FromFile(@"\\90.0.0.8\d\Nouman's Development\SizaPayRoll For Backup\backup\SizaPayRoll\icons\images (3).jpg");
                StripStatusLabel.ForeColor = Color.Green;
                StripStatusLabel.Text = "Increment export to excel successfully...";
                xlWorkBook.Close(true, misValue, misValue);
                xlApp.Quit();
                releaseObject(xlWorkSheet);
                releaseObject(xlWorkBook);
                releaseObject(xlApp);
            }
            else if (myResult == System.Windows.Forms.DialogResult.Cancel)  // <- Changes here !!!
            {

            }
}
... because if you get a DialogResult from the SaveFileDialog the SaveFileDialog is no more existing ...

Please try it ...
 
Share this answer
 
Comments
Richard MacCutchan 20-Dec-16 7:01am    
Well spotted.
Ralf Meier 21-Dec-16 3:20am    
Thanks for your vote, Richard

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900