Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [SOLVED]: Not Getting Proper Output From Compiled EXE File

[SOLVED]: Not Getting Proper Output From Compiled EXE File

Scheduled Pinned Locked Moved C#
helpvisual-studio
23 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Bastar Media

    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.

    M Offline
    M Offline
    Matt T Heffron
    wrote on last edited by
    #13

    This is beginning to look like a Heisenbug[^] ;)

    "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

    1 Reply Last reply
    0
    • G Gonzoox

      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!

      B Offline
      B Offline
      Bastar Media
      wrote on last edited by
      #14

      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.

      1 Reply Last reply
      0
      • B Bastar Media

        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.

        W Offline
        W Offline
        Wendelius
        wrote on last edited by
        #15

        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.

        B 2 Replies Last reply
        0
        • W Wendelius

          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.

          B Offline
          B Offline
          Bastar Media
          wrote on last edited by
          #16

          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 231

          And 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
          
          W 1 Reply Last reply
          0
          • B Bastar Media

            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 231

            And 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
            
            W Offline
            W Offline
            Wendelius
            wrote on last edited by
            #17

            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.

            B 1 Reply Last reply
            0
            • W Wendelius

              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.

              B Offline
              B Offline
              Bastar Media
              wrote on last edited by
              #18

              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.

              W 1 Reply Last reply
              0
              • W Wendelius

                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.

                B Offline
                B Offline
                Bastar Media
                wrote on last edited by
                #19

                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.

                1 Reply Last reply
                0
                • B Bastar Media

                  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.

                  W Offline
                  W Offline
                  Wendelius
                  wrote on last edited by
                  #20

                  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 :)

                  B 2 Replies Last reply
                  0
                  • W Wendelius

                    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 :)

                    B Offline
                    B Offline
                    Bastar Media
                    wrote on last edited by
                    #21

                    Ok, I will keep that in mind for my future projects.

                    1 Reply Last reply
                    0
                    • W Wendelius

                      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 :)

                      B Offline
                      B Offline
                      Bastar Media
                      wrote on last edited by
                      #22

                      Ok dear, I will keep that in mind for my future projects.

                      1 Reply Last reply
                      0
                      • OriginalGriffO OriginalGriff

                        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...

                        U Offline
                        U Offline
                        User 11963318
                        wrote on last edited by
                        #23

                        Hi Everyone, I need some help regarding WordPress Blogs, can anyone help me out pls ?
                        Regards,
                        Mehwish
                        https://www.facebook.com/Techionix
                        http://techionix.com/

                        1 Reply Last reply
                        0
                        Reply
                        • Reply as topic
                        Log in to reply
                        • Oldest to Newest
                        • Newest to Oldest
                        • Most Votes


                        • Login

                        • Don't have an account? Register

                        • Login or register to search.
                        • First post
                          Last post
                        0
                        • Categories
                        • Recent
                        • Tags
                        • Popular
                        • World
                        • Users
                        • Groups