Program works in debug but exe has errors
-
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
-
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
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
-
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
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
-
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
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
-
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
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 ClassIs 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
-
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 ClassIs 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
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
-
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
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