|
-
Jun 28th, 2012, 07:33 AM
#1
Thread Starter
Lively Member
[RESOLVED] Unexpected Error
Ok i made a program it worked fine. I changed Net Framework to 3.5, then back to version 4 (i was testing something)
It now works fine.
I run the program from vb.net in debug mode and everythign works fine.
I clean the build,
I then build the project.
I then run the built exe but then it shows an error. The error point to this code:
Code:
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
If Not My.Computer.FileSystem.DirectoryExists(wdir) Then
My.Computer.FileSystem.CreateDirectory(wdir)
End If
If Not My.Settings.prevsearch Is Nothing Then
If My.Settings.prevsearch <> "" Then
txt_g_url.Text = My.Settings.prevsearch
MsgBox(wdir)
End If
End If
For Each item As String In My.Settings.prevurl
If Not txturl.Items.Contains(item) Then
txturl.Items.Add(item)
End If
Next
End Sub
I cant figure out why this is. The main point is it works in debug but not after its built.
heres the exception error:
Code:
************** Exception Text **************
System.NullReferenceException: Object reference not set to an instance of an object.
at RAF_WEB.Form1.Form1_Load(Object sender, EventArgs e) in H:\Files\VB NET\Projects\RAF_WEB\RAF_WEB\Form1.vb:line 2311
at System.EventHandler.Invoke(Object sender, EventArgs e)
at System.Windows.Forms.Form.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.WmShowWindow(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
at System.Windows.Forms.Form.WmShowWindow(Message& m)
at System.Windows.Forms.Form.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
Last edited by rafhelp; Jun 28th, 2012 at 07:36 AM.
-
Jun 28th, 2012, 11:31 AM
#2
Junior Member
Re: Unexpected Error
The issue is likely related to your development environment. I believe by default your development environment expects YOU to handle certain exceptions, Null Reference being one of them.
To fix, in VS 2008 (Similar for other versions of VS) go to:
(On the toolbar) Debug > Exceptions (Or CTRL + ALT + E)
This brings up a list of all exceptions and how they're handled.
Navigate the Tree List to:
Common Runtime Exceptions > System > System.NullReferenceException
Check the checkbox that says "THROWN". Click OK and run the program via Debug Mode. The program should now throw that same exception and you'll see exactly what's going on.
Enjoy 
P.S. This happened to me 2 days ago ;-).
Last edited by nycdev; Jun 28th, 2012 at 11:37 AM.
-
Jun 28th, 2012, 11:50 AM
#3
Thread Starter
Lively Member
Re: Unexpected Error
 Originally Posted by nycdev
The issue is likely related to your development environment. I believe by default your development environment expects YOU to handle certain exceptions, Null Reference being one of them.
To fix, in VS 2008 (Similar for other versions of VS) go to:
(On the toolbar) Debug > Exceptions (Or CTRL + ALT + E)
This brings up a list of all exceptions and how they're handled.
Navigate the Tree List to:
Common Runtime Exceptions > System > System.NullReferenceException
Check the checkbox that says "THROWN". Click OK and run the program via Debug Mode. The program should now throw that same exception and you'll see exactly what's going on.
Enjoy
P.S. This happened to me 2 days ago ;-).
tried that, also selected THROWN for all system exceptions. still same thing. works in debug, no errors, after i build, double click on exe in the bin/release folder and the error is shown, if i press continue it works fine...
Code:
Object reference not set to an instance of an object
-
Jun 28th, 2012, 11:55 AM
#4
Junior Member
Re: Unexpected Error
Hm, strange. Does the exe in the debug file have a modified date of just when you built the project? Maybe it's not being updated?
-
Jun 28th, 2012, 12:26 PM
#5
Thread Starter
Lively Member
Re: Unexpected Error
its being updated, i checked by deleting the old one
-
Jun 28th, 2012, 12:30 PM
#6
Junior Member
Re: Unexpected Error
Since you have so few lines of code, at this point I would just suggest stepping through it.
Btw not sure if you're aware, but you can run the program via the EXE and then still debug it using VS by click Tools > Attach to Process > [YourFile.exe].
I would do that and step through the Form1_Load carefully and examine each item and look for a "Nothing" somewhere.
For example maybe My.Settings is "Nothing".
I also notice you have
vb Code:
If Not My.Settings.prevsearch Is Nothing Then
...
End If
For Each item As String In My.Settings.prevurl
...
Next
You're checking if prevurl is nothing in the first block but not the second, so if there's a chance it's nothing you should not do the loop without first checking the same "if not my.settings.prevurl is nothing"
-
Jun 28th, 2012, 12:44 PM
#7
Re: Unexpected Error
- Which line exactly is throwing the exception
- Have you looked at the settings file (user.config)
Use the following to get the user.config path
Code:
Imports System.Configuration
Module FolderLocation
''' <summary>
''' Get the user's config file
''' </summary>
''' <returns></returns>
''' <remarks>
''' add a reference to System.Configuration.dll
''' </remarks>
Public Function UserConfigFolder() As String
Return ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.PerUserRoamingAndLocal).FilePath.Replace("\user.config", "")
End Function
End Module
Uage
Code:
MsgBox(UserConfigFolder)
-
Jun 28th, 2012, 12:49 PM
#8
Thread Starter
Lively Member
Re: Unexpected Error
 Originally Posted by nycdev
Since you have so few lines of code, at this point I would just suggest stepping through it.
Btw not sure if you're aware, but you can run the program via the EXE and then still debug it using VS by click Tools > Attach to Process > [YourFile.exe].
I would do that and step through the Form1_Load carefully and examine each item and look for a "Nothing" somewhere.
For example maybe My.Settings is "Nothing".
I also notice you have
vb Code:
If Not My.Settings.prevsearch Is Nothing Then
...
End If
For Each item As String In My.Settings.prevurl
...
Next
You're checking if prevurl is nothing in the first block but not the second, so if there's a chance it's nothing you should not do the loop without first checking the same "if not my.settings.prevurl is nothing"
Done...
The last thing you said worked. Logically does not make sense as it worked before.. is there any way to modify settings so that it does not throw an error if the my.computer.settings.setting is empty.
for example i create a collection of string setting in the program which is always starts as an empty collection but if you try to add to it it always throws an error, so you HAVE to check if the setting is "Nothing"
-
Jun 28th, 2012, 12:52 PM
#9
Junior Member
Re: [RESOLVED] Unexpected Error
I'm not familiar with the My.Settings but can';t you do one check at the beginning of the program and if it's empty instantiate it to an empty collection?
Something like:
vb Code:
If My.Settings is nothing Then My.Settings = New SomeCollection(of SomeType) End If
-
Jun 28th, 2012, 12:52 PM
#10
Re: Unexpected Error
 Originally Posted by rafhelp
Done...
The last thing you said worked. Logically does not make sense as it worked before.. is there any way to modify settings so that it does not throw an error if the my.computer.settings.setting is empty.
for example i create a collection of string setting in the program which is always starts as an empty collection but if you try to add to it it always throws an error, so you HAVE to check if the setting is "Nothing"
Look at the following thread
http://www.vbforums.com/showthread.php?t=580949
-
Jun 28th, 2012, 12:53 PM
#11
Thread Starter
Lively Member
Re: [RESOLVED] Unexpected Error
 Originally Posted by nycdev
I'm not familiar with the My.Settings but can';t you do one check at the beginning of the program and if it's empty instantiate it to an empty collection?
Something like:
vb Code:
If My.Settings is nothing Then
My.Settings = New SomeCollection(of SomeType)
End If
thats what i normally do
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|