[SOLVED]: Not Getting Proper Output From Compiled EXE File
-
Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.
Wow. You're expecting a lot from us here. No code, only a description of the problem. I'm not sure you're going to get much more help than this I'm afraid.
-
Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.
Have you recompiled your project making sure that 'release' is selected in the configuration dropdown? It could be that you have 'debug' selected and when you run from the IDE you are running in debug mode but never recompiling in release mode.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
-
Wow. You're expecting a lot from us here. No code, only a description of the problem. I'm not sure you're going to get much more help than this I'm afraid.
Hearty Sorry, Here is the code:
public void WardList()
{
#region Load Values...
int count = 1;
List WWList = new List();
Engine E = new Engine();
SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
SQLiteDataReader RDR = CMD.ExecuteReader();while (RDR.Read()) { WardWise WW = new WardWise(); WW.Serial = count; WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]); WW.WardCount = WardCount(WW.WardNumber); WW.Name = RDR\["NAME"\].ToString(); WW.Manager = RDR\["MANAGER"\].ToString(); WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0; WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0; WW.Balance = WW.TotalTax - WW.TotalPaid; count++; WWList.Add(WW); } #endregion using (ExcelPackage EP = new ExcelPackage(Masters, Template)) { double hook = 8; ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\]; foreach (WardWise WW in WWList) { Sheet.Cells\["A" + hook\].Value = WW.Serial; Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]"; Sheet.Cells\["C" + hook\].Value = WW.Name; Sheet.Cells\["D" + hook\].Value = WW.Manager; Sheet.Cells\["E" + hook\].Value = WW.TotalTax; Sheet.Cells\["F" + hook\].Value = WW.TotalPaid; Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook); hook++; } Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin; Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1); Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true; Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style = Sheet.Cells\["G" + (h
-
Have you recompiled your project making sure that 'release' is selected in the configuration dropdown? It could be that you have 'debug' selected and when you run from the IDE you are running in debug mode but never recompiling in release mode.
“That which can be asserted without evidence, can be dismissed without evidence.”
― Christopher Hitchens
Hi GuyThiebaut, I tried that too, but getting no success.
-
Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.
Hearty Sorry for not posting the code: Here is the code:
public void WardList()
{
#region Load Values...
int count = 1;
List WWList = new List();
Engine E = new Engine();
SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
SQLiteDataReader RDR = CMD.ExecuteReader();while (RDR.Read()) { WardWise WW = new WardWise(); WW.Serial = count; WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]); WW.WardCount = WardCount(WW.WardNumber); WW.Name = RDR\["NAME"\].ToString(); WW.Manager = RDR\["MANAGER"\].ToString(); WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0; WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0; WW.Balance = WW.TotalTax - WW.TotalPaid; count++; WWList.Add(WW); } #endregion using (ExcelPackage EP = new ExcelPackage(Masters, Template)) { double hook = 8; ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\]; foreach (WardWise WW in WWList) { Sheet.Cells\["A" + hook\].Value = WW.Serial; Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]"; Sheet.Cells\["C" + hook\].Value = WW.Name; Sheet.Cells\["D" + hook\].Value = WW.Manager; Sheet.Cells\["E" + hook\].Value = WW.TotalTax; Sheet.Cells\["F" + hook\].Value = WW.TotalPaid; Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook); hook++; } Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin; Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1); Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true; Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style =
-
Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.
Start by looking at the input and output files: are you using absolute paths? Relative paths? Are they all looking at the same files? What are the folders like - do they have suitable permissions, if they aren't the same? Are the debug and release versions running on the same computer? Under the same user? What happens if you execute the debug version directly in the same way you did with the release? Do you get any error messages? Are you swallowing any exceptions? You need to get information on exactly what is happening - we can't run your code in isolation! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Hearty Sorry for not posting the code: Here is the code:
public void WardList()
{
#region Load Values...
int count = 1;
List WWList = new List();
Engine E = new Engine();
SQLiteCommand CMD = new SQLiteCommand(E.SelectSQL("WARDS") + " ORDER BY [WARDNUMBER];", E.Conn);
SQLiteDataReader RDR = CMD.ExecuteReader();while (RDR.Read()) { WardWise WW = new WardWise(); WW.Serial = count; WW.WardNumber = Convert.ToInt32(RDR\["WARDNUMBER"\]); WW.WardCount = WardCount(WW.WardNumber); WW.Name = RDR\["NAME"\].ToString(); WW.Manager = RDR\["MANAGER"\].ToString(); WW.TotalTax = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber) : 0; WW.TotalPaid = WardExists(WW.WardNumber) ? WardWiseTax(WW.WardNumber, false) : 0; WW.Balance = WW.TotalTax - WW.TotalPaid; count++; WWList.Add(WW); } #endregion using (ExcelPackage EP = new ExcelPackage(Masters, Template)) { double hook = 8; ExcelWorksheet Sheet = EP.Workbook.Worksheets\["AWW"\]; foreach (WardWise WW in WWList) { Sheet.Cells\["A" + hook\].Value = WW.Serial; Sheet.Cells\["B" + hook\].Value = WW.WardNumber + " \[" + WW.WardCount + "\]"; Sheet.Cells\["C" + hook\].Value = WW.Name; Sheet.Cells\["D" + hook\].Value = WW.Manager; Sheet.Cells\["E" + hook\].Value = WW.TotalTax; Sheet.Cells\["F" + hook\].Value = WW.TotalPaid; Sheet.Cells\["G" + hook\].Formula = ("E" + hook) + "-" + ("F" + hook); hook++; } Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Top.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Bottom.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Left.Style = Sheet.Cells\["A8:G" + (hook - 1)\].Style.Border.Right.Style = ExcelBorderStyle.Thin; Sheet.Cells\["G" + (hook + 1)\].Formula = string.Format("SUM(G8:G{0})", hook - 1); Sheet.Cells\["G" + (hook + 1)\].Style.Font.Bold = true; Sheet.Cells\["G" + (hook + 1)\].Style.Border.Top.Style =
-
Start by looking at the input and output files: are you using absolute paths? Relative paths? Are they all looking at the same files? What are the folders like - do they have suitable permissions, if they aren't the same? Are the debug and release versions running on the same computer? Under the same user? What happens if you execute the debug version directly in the same way you did with the release? Do you get any error messages? Are you swallowing any exceptions? You need to get information on exactly what is happening - we can't run your code in isolation! :laugh:
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
Hi OriginalGriff, The code for input and output files is
private static readonly string TemplatesFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
private static readonly string MastersFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
private static FileInfo Template = new FileInfo(TemplatesFile);
private static FileInfo Masters;The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll
Even though, I am getting a nice excel report. But not from EXE file. Regards.
-
Hi OriginalGriff, The code for input and output files is
private static readonly string TemplatesFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
private static readonly string MastersFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
private static FileInfo Template = new FileInfo(TemplatesFile);
private static FileInfo Masters;The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll
Even though, I am getting a nice excel report. But not from EXE file. Regards.
You are using relative paths - relative to the current directory, which will default to the folder the app is run from - so check that you are looking in the right folder when you run the code. And I'd look in the debugger at where the exceptions are happening and why - it may be that they are relevant to your problem, and it works because the debugger is trapping the exception and letting you know it occurred. In the "undebugged" version, they may be stopping your code running. If you look on the VS Debug menu, you can tell it to break on all exceptions, caught or not.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
-
Hi OriginalGriff, The code for input and output files is
private static readonly string TemplatesFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
private static readonly string MastersFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
private static FileInfo Template = new FileInfo(TemplatesFile);
private static FileInfo Masters;The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll
Even though, I am getting a nice excel report. But not from EXE file. Regards.
I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?
I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
-
I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?
I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
This isn't going to help since he states that the program works as intended when run under the IDE, which of course, is what he'd be doing in order to debug.
"Fairy tales do not tell children the dragons exist. Children already know that dragons exist. Fairy tales tell children the dragons can be killed." - G.K. Chesterton
-
Hi OriginalGriff, The code for input and output files is
private static readonly string TemplatesFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "ReportsTemplate.xlsx");
private static readonly string MastersFile =
Path.Combine(Directories.CurrentDirectory, "Reports", "Master.xlsx");
private static FileInfo Template = new FileInfo(TemplatesFile);
private static FileInfo Masters;The folders have suitable permissions. Yes, Debug and Release version are on the same computer, under same user. When I run the EXE file I am not getting any output on both Debug and Release versions, but getting nice excel report when I run it from the IDE. I am getting no errors. But, in the output window of the IDE, I am getting lots of First Chance Exceptions like this:
A first chance exception of type 'System.ObjectDisposedException' occurred in System.Data.SQLite.dll
Even though, I am getting a nice excel report. But not from EXE file. Regards.
-
I'd recommend that you debug it line by line and check if everything is happening as expected, is line 1 getting the values? how about line 2? 3? and so on. is every object instanced correctly? must of the times something really small is what is causing the problem. When you execute the code inside visual studio, the application runs from the debug/release folder, are you executing it from the same location? or you copied the exe to a different folder? could it be is the paths you're using to read and write are not returning a valid path?
I want to die like my grandfather- asleep, not like the passengers in his car, screaming!
Hi Gonzoox, Thanks for the reply. Yes, I had executed and executing the program from the same folder as it was created by the IDE. Moreover, debugging line by line, I am getting proper watch values on each variables. Even though, I will debug it once more as you said. Thanks.
-
Hello there, WORK: I am working on a project, in which the output of some methods create a excel sheet. PROBLEM: When I run the project from IDE, the excel file is created properly and with all data from List. But, when its run from the compiled EXE file, I am getting no output in the excel file. Please help.
As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.
-
As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.
Hi Mika, As you said I designed a logfile stream writer and now I got my log file full of these two errors:
ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber) in Reporting.cs:line 209
19/09/2015 12:18:39 PM : ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber, Boolean TotalPaid) in Reporting.cs:line 231And here is the code where I am getting those errors:
private double WardWiseTax(Int32 WardNumber)
{
double TT = 0;
try
{
Engine E = new Engine();
SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
Calculate CT = new Calculate();while (CUSTRDR.Read()) // Here is the error (209) TT += CT.LedgerBalance(CUSTRDR\["DEMAND"\].ToString())\[1\]; CUSTCMD.Dispose(); CUSTRDR.Dispose(); CT.Dispose(); return TT; } catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; } } private double WardWiseTax(Int32 WardNumber, bool TotalPaid) { double TT = 0; try { Engine E = new Engine(); SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn); CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber); SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader(); Calculate CT = new Calculate(); while (CUSTRDR.Read()) // Here is the error (231) { TT += CT.Le
-
Hi Mika, As you said I designed a logfile stream writer and now I got my log file full of these two errors:
ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber) in Reporting.cs:line 209
19/09/2015 12:18:39 PM : ERROR: Cannot access a disposed object.
Object name: 'SQLiteConnection'. TARGET: Void CheckDisposed() STACK TRACE: at System.Data.SQLite.SQLiteConnection.CheckDisposed()
at System.Data.SQLite.SQLiteConnection.get_State()
at System.Data.SQLite.SQLiteDataReader.CheckClosed()
at System.Data.SQLite.SQLiteDataReader.Read()
at PTMS.Classes.Reports.Reporting.WardWiseTax(Int32 WardNumber, Boolean TotalPaid) in Reporting.cs:line 231And here is the code where I am getting those errors:
private double WardWiseTax(Int32 WardNumber)
{
double TT = 0;
try
{
Engine E = new Engine();
SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn);
CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber);
SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader();
Calculate CT = new Calculate();while (CUSTRDR.Read()) // Here is the error (209) TT += CT.LedgerBalance(CUSTRDR\["DEMAND"\].ToString())\[1\]; CUSTCMD.Dispose(); CUSTRDR.Dispose(); CT.Dispose(); return TT; } catch (Exception ex) { LogEvent.WriteErrorLog(ex); return 0; } } private double WardWiseTax(Int32 WardNumber, bool TotalPaid) { double TT = 0; try { Engine E = new Engine(); SQLiteCommand CUSTCMD = new SQLiteCommand(E.SelectSQL("CUSTOMERS", "WARDNUMBER"), E.Conn); CUSTCMD.Parameters.AddWithValue("WARDNUMBER", WardNumber); SQLiteDataReader CUSTRDR = CUSTCMD.ExecuteReader(); Calculate CT = new Calculate(); while (CUSTRDR.Read()) // Here is the error (231) { TT += CT.Le
As far as I can see the problem is that the connection is stored in another class, perhaps a static one. Based on this any method can dispose the connection and you would see this as a problem in the next call when the disposed connection is trying to be used. So probably the dispose happens elsewhere. To correct this you would need to do a little bit of a re-design. I've touched this problem in Properly executing database operations[^]. Have a look at the initial version and differences in version 2. I think that clarifies the situation.
-
As others have already said, more info would be needed in order to solve the problem. However, I understand the difficulty since the project works in IDE but not as an executable. So what I suggest is that you add some kind of 'messaging' into the code. It could be writing a log file or something similar or simply just show message boxes. Add these messages to the code and run the exe. This should give you better understanding about the execution. Try to add relevant info into the messages such as working directory or the full paths of the file names etc. With the messages you see more easily what happens and what code is reached and what is not.
Thanks a lot Mika, I found a solution. Actually the object SQLiteconnection was disposing and hence not giving the output while running from EXE, but this exception was not being catching while running from the IDE. I removed all the dispose statements in my project and not its running fine. And thanks a lot for you log file idea, it helped me a lot to detect the error.
-
As far as I can see the problem is that the connection is stored in another class, perhaps a static one. Based on this any method can dispose the connection and you would see this as a problem in the next call when the disposed connection is trying to be used. So probably the dispose happens elsewhere. To correct this you would need to do a little bit of a re-design. I've touched this problem in Properly executing database operations[^]. Have a look at the initial version and differences in version 2. I think that clarifies the situation.
Hi Mika, Although I am getting the desired result, I know removing all disposed statements is not a perfect solution. Will you please help me to tell Where actually I should apply dispose statement. Regards.
-
Thanks a lot Mika, I found a solution. Actually the object SQLiteconnection was disposing and hence not giving the output while running from EXE, but this exception was not being catching while running from the IDE. I removed all the dispose statements in my project and not its running fine. And thanks a lot for you log file idea, it helped me a lot to detect the error.
-
Glad to be of service :) I would recommend not using shared connection objects but having
using
statements instead as explained in the article. That would make the code much simple and robust in the long run :)Ok, I will keep that in mind for my future projects.