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. Visual Basic
  4. Program works in debug but exe has errors

Program works in debug but exe has errors

Scheduled Pinned Locked Moved Visual Basic
csharpvisual-studiodebugginghelp
7 Posts 2 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.
  • J Offline
    J Offline
    jonathan15
    wrote on last edited by
    #1

    I have a small program in vb.net that until today worked perfectly. All i did was change some icons (form icons and the program icon) and recompile . Now i am seeing some odd behavior and cant figure out why. The program still works perfectly when run from the IDE (VS2003) but the built exe generates an error which i can trap. The other odd thing is that the file size of the exe has dropped from 567kb to 450kb. Any ideas? Jon

    D 1 Reply Last reply
    0
    • J jonathan15

      I have a small program in vb.net that until today worked perfectly. All i did was change some icons (form icons and the program icon) and recompile . Now i am seeing some odd behavior and cant figure out why. The program still works perfectly when run from the IDE (VS2003) but the built exe generates an error which i can trap. The other odd thing is that the file size of the exe has dropped from 567kb to 450kb. Any ideas? Jon

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      jonathan15 wrote:

      but the built exe generates an error

      And that would be ______________________________?? Without that, it's pretty impossible to tell you anything useful. The code that generated the error would also help. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      J 2 Replies Last reply
      0
      • D Dave Kreskowiak

        jonathan15 wrote:

        but the built exe generates an error

        And that would be ______________________________?? Without that, it's pretty impossible to tell you anything useful. The code that generated the error would also help. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        J Offline
        J Offline
        jonathan15
        wrote on last edited by
        #3

        The error is "Object reference not set to an instance of an object. at In_Sync.frmMain.StartMe() in C:\Visual Studio Projects\In-Sync2\In-Sync\Forms\Form1.vb:line 229" which i log in the event log. This relates to this section of code: For Each parkToChange In setupDetail.Parks SetAvail(parkToChange.ParkCode) Next Setupdetail.parks is a shared property so in form1 this is not instanced it is simply called. Of course in setupdetail an instance of the 'Parks' object is created and populated with 'Park' Items as in this next bit of code (setupdetail.loadvalues). Dim myparks As parks = New parks If Not mFirstRun Then Do While secureReader.Read Dim mypark As park = New park(secureReader.GetString(1), crypto.Decrypt(secureReader.GetString(3)), secureReader.GetString(0)) myparks.Add(mypark) Loop Else Form1 is set as the startup object and should call Setupdetail.loadvalues before calling the startme rutine which is generating the error. As in the code below: Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() setupDetail.LoadValues() StartMe() 'Add any initialization after the InitializeComponent() call End Sub The thing is it all works when run through the IDE so debugging is not possible. I have tried to log events at key stages and found that Setupdetail.loadevents is never entered. So that is why i get the error because setupdetail.parks does not exist. My real question is why is it never run. Could the form be corrupted. Jon

        D 1 Reply Last reply
        0
        • D Dave Kreskowiak

          jonathan15 wrote:

          but the built exe generates an error

          And that would be ______________________________?? Without that, it's pretty impossible to tell you anything useful. The code that generated the error would also help. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          J Offline
          J Offline
          jonathan15
          wrote on last edited by
          #4

          Just Tested it some more and it is definately not entering setupdetail.loadvalues when run from the exe but it is when run through the IDE. This happens even if i move the call from sub new to the start of startme routine. Why would it do this? Jon

          1 Reply Last reply
          0
          • J jonathan15

            The error is "Object reference not set to an instance of an object. at In_Sync.frmMain.StartMe() in C:\Visual Studio Projects\In-Sync2\In-Sync\Forms\Form1.vb:line 229" which i log in the event log. This relates to this section of code: For Each parkToChange In setupDetail.Parks SetAvail(parkToChange.ParkCode) Next Setupdetail.parks is a shared property so in form1 this is not instanced it is simply called. Of course in setupdetail an instance of the 'Parks' object is created and populated with 'Park' Items as in this next bit of code (setupdetail.loadvalues). Dim myparks As parks = New parks If Not mFirstRun Then Do While secureReader.Read Dim mypark As park = New park(secureReader.GetString(1), crypto.Decrypt(secureReader.GetString(3)), secureReader.GetString(0)) myparks.Add(mypark) Loop Else Form1 is set as the startup object and should call Setupdetail.loadvalues before calling the startme rutine which is generating the error. As in the code below: Public Sub New() MyBase.New() 'This call is required by the Windows Form Designer. InitializeComponent() setupDetail.LoadValues() StartMe() 'Add any initialization after the InitializeComponent() call End Sub The thing is it all works when run through the IDE so debugging is not possible. I have tried to log events at key stages and found that Setupdetail.loadevents is never entered. So that is why i get the error because setupdetail.parks does not exist. My real question is why is it never run. Could the form be corrupted. Jon

            D Offline
            D Offline
            Dave Kreskowiak
            wrote on last edited by
            #5

            Let me get this straight:

            Public Class Form1
            Public Sub New()
            MyBase.New()
             
            'This call is required by the Windows Form Designer.
            InitializeComponent()
            setupDetail.LoadValues()
            StartMe()
            'Add any initialization after the InitializeComponent() call
            End Sub
             
            Public Sub StartMe()
            For Each parkToChange In setupDetail.Parks
            SetAvail(parkToChange.ParkCode)
            Next
            End Sub
            End Class
             
            Public Class setupDetail
            Public Shared Property
            blah, blah, blah
            End Property
             
            Public Shared LoadValues()
            Dim myparks As parks = New parks
            If Not mFirstRun Then
            Do While secureReader.Read
            Dim mypark As park = New park(secureReader.GetString(1), _
            crypto.Decrypt(secureReader.GetString(3)), secureReader.GetString(0))
            myparks.Add(mypark)
            Loop
            Else
            ...
            End If
            End Sub
            End Class

            Is this about correct? Why is this setupDetail class using all Shared stuff? What you're doing would be much better off as a normal class where all the methods to populate and manipulate the Parks collection are public, not shared. Everything you're doing is manipulating public data from outside the class that contains it. This is a no-no according to normal OOP practices. I'd rewrite your Parks collection into its own class, supplying public methods to initialize itself and manipulate the collection and its data. You can then create an instance of this class, even follow the Singleton Pattern[^] to create a globally single instance of it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            J 1 Reply Last reply
            0
            • D Dave Kreskowiak

              Let me get this straight:

              Public Class Form1
              Public Sub New()
              MyBase.New()
               
              'This call is required by the Windows Form Designer.
              InitializeComponent()
              setupDetail.LoadValues()
              StartMe()
              'Add any initialization after the InitializeComponent() call
              End Sub
               
              Public Sub StartMe()
              For Each parkToChange In setupDetail.Parks
              SetAvail(parkToChange.ParkCode)
              Next
              End Sub
              End Class
               
              Public Class setupDetail
              Public Shared Property
              blah, blah, blah
              End Property
               
              Public Shared LoadValues()
              Dim myparks As parks = New parks
              If Not mFirstRun Then
              Do While secureReader.Read
              Dim mypark As park = New park(secureReader.GetString(1), _
              crypto.Decrypt(secureReader.GetString(3)), secureReader.GetString(0))
              myparks.Add(mypark)
              Loop
              Else
              ...
              End If
              End Sub
              End Class

              Is this about correct? Why is this setupDetail class using all Shared stuff? What you're doing would be much better off as a normal class where all the methods to populate and manipulate the Parks collection are public, not shared. Everything you're doing is manipulating public data from outside the class that contains it. This is a no-no according to normal OOP practices. I'd rewrite your Parks collection into its own class, supplying public methods to initialize itself and manipulate the collection and its data. You can then create an instance of this class, even follow the Singleton Pattern[^] to create a globally single instance of it. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              J Offline
              J Offline
              jonathan15
              wrote on last edited by
              #6

              Yep, I accept that this isnt the best way to do things and when i planned it there were only 2 shared properties in this class and 1 shared method to get the data. It does need redoing but at the moment it works so im not going to touch it. With regard to the initial problem, i rebuilt the application by opening a new project and adding the existing files (except form1) then re-created form1 from scratch. Guess what, It works. Thanks for your help though. I appreciate you spending the time to look at it for me. Thanks Jonathan

              D 1 Reply Last reply
              0
              • J jonathan15

                Yep, I accept that this isnt the best way to do things and when i planned it there were only 2 shared properties in this class and 1 shared method to get the data. It does need redoing but at the moment it works so im not going to touch it. With regard to the initial problem, i rebuilt the application by opening a new project and adding the existing files (except form1) then re-created form1 from scratch. Guess what, It works. Thanks for your help though. I appreciate you spending the time to look at it for me. Thanks Jonathan

                D Offline
                D Offline
                Dave Kreskowiak
                wrote on last edited by
                #7

                jonathan15 wrote:

                It does need redoing but at the moment it works so im not going to touch it.

                jonathan15 wrote:

                With regard to the initial problem, i rebuilt the application by opening a new project and adding the existing files (except form1) then re-created form1 from scratch. Guess what, It works.

                If you needed to do this to get it to work again, you need to rebuild the class quicker than your think. Is what you did to get it to work again a supportable solution? I don't think so. I think you're living on borrowed time now. I'd be rewriting this thing first thing in the morning so any future changes to the code don't break it again. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                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