Click here to Skip to main content
15,922,155 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am sorry if I am being a nuisance; I know I have asked many questions.

This exception was originally thrown at this call stack:
[External Code]
ArchiveDataSheets.frmArchiveDataSheets.frmArchiveDataSheets() in frmArchiveDataSheets.cs

To my knowledge, I have made no changes to the code except the Sheet Move procedure; if I did, it was by mistake.

I looked at the code, and it is not even getting to the "using System;" I have no idea how to troubleshoot this error further.

C#
private void cmdArhcive_Click(object sender, EventArgs e)
        {

            try
            {
                objApp.DisplayAlerts = false;
                objApp.Workbooks.get_Item(RegGlobals.excelFileName);
                objApp.DisplayAlerts = true;
                this.Hide();
                frmArchiveDataSheets pantryForm = new frmArchiveDataSheets();
                pantryForm.Show();
            }
            catch
            {
                objApp = new Excel.Application();
                theWorkbook = objApp.Workbooks.Open(RegGlobals.StrPath);
                this.Hide();
                frmArchiveDataSheets pantryForm = new frmArchiveDataSheets();
                pantryForm.Show();
            }
        }


The line in question is
C#
frmArchiveDataSheets pantryForm = new frmArchiveDataSheets();


What I have tried:

Rename the form
Comment out the last code I wrote.
Search everywhere for frmArchiveDataSheets
Rename the form
Search everywhere for cmdArhcive_Click
Posted
Updated 8-Aug-22 18:42pm
v4

1 solution

Firstly, a using statement such as using System; is not executable, so the code never "gets to" execute it.

The error message is saying that something failed in a constructor - probably the frmArchiveDataSheets constructor - but it doesn't say what.

The error message is is only part of what you need: you need the whole Exception object to start working out what is happening. So begin by changing your code so you can access the error details:
C#
try
{
    ...
}
catch (Exception ex)
{
    ...
}
Now run your code in the debugger and put a breakpoint on the first line in the catch block.

When the breakpoint hits, look at ex and it'll give you a lot of information, including an InnerException which gives you more detail - this is often something like Object reference not set to an instance of an object and the information as to where it happened.

So start there: look at the error message, and at the code that generated the error, and break point that. Run your code again in the debugger, and look at what might have caused the inner exception.

Sorry, but we can't do that for you!
 
Share this answer
 

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