473,385 Members | 1,927 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to handle System.NullReferenceException??

111 100+
hii all,

im a fresher, and new to the programming side..
when im trying to execute a project...
m getting an exception at the line : If MyDocument.length=0


the code goes on like this:

Public Function MyGet(ByVal MyKey As String) As String
Dim XmlDocument As New XmlDocument
Dim XmlNode As XmlNode
Dim XmlRoot As XmlNode
Dim XmlKey As XmlNode
Dim XmlValue As XmlNode

exception--->> If DocumentName.Length = 0 Then
Return ""
Exit Function
End If

XmlDocument.Load(MyDocument)
XmlNode = XmlDocument.DocumentElement.SelectSingleNode("/configuration/appSettings/add[@key=""" & MyKey & """]")

If XmlNode Is Nothing Then
'
' The node does not exist, let's create it
'
MyGet = ""

Else
'
' The node exist, save the new value
'
MyGet = XmlNode.Attributes.GetNamedItem("value").Value

End If
XmlDocument.Save(MyDocument)
XmlDocument = Nothing

Return MyGet

End Function



now can u tell me the solution...

thnks all...
Apr 25 '07 #1
2 2596
shweta123
692 Expert 512MB
Hi,

Put the whole code under
Try

catch ex as Exception
''''''''''you can get here exception message ,source etc.
msgbox(ex.Message)
msgbox(ex.Source)

end Try
Apr 25 '07 #2
radcaesar
759 Expert 512MB
If DocumentName.Length == 0

Check whether it returns NULL by DEBUG the code. Put break point and Watch it.
Apr 25 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Terrence | last post by:
I am doing some of the C# walkthroughs to transition from VB to C#. When I try to execute static void Main() { Aplication.Run(new Form1()) } I raise a 'System.NullReferenceException" in...
1
by: Rafael | last post by:
Hi, I hope I can find some help for this problem IDE: Visual Studio.NET 2003 Developer Editio Language: C# Problem: "An unhandled exception of type 'System.NullReferenceException' occurred in...
0
by: muralidharan | last post by:
WebForm1.aspx Code: <%@ Register TagPrefix="ComponentArt" Namespace="ComponentArt.Web.UI" Assembly="ComponentArt.Web.UI" %> <ComponentArt:TreeView id="TreeView1" Height="520"...
5
by: Vitling | last post by:
For no apparent reason, a NullReference exception is thrown in system.dll (System.Net.Sockets.OverlappedAsyncResult.CompletionPortCallback). Since I only get a disassembly from Visual Studio, it...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
1
by: msnews.microsoft.com | last post by:
I'm trying to fill an array of objects but when I add the first object I get a NullReferenceException. ----------------------------------------------------------------------------...
2
by: sxiao | last post by:
Hi, there I got a NullReferenceException when there are more than one users trying to open the same page at the same time. The senerio is: Two users logged into the web application using the...
6
by: William Mild | last post by:
I must be getting brain fried. I can't see the error. Create a new web form with the following code begind: Public Class test Inherits System.Web.UI.Page Public Class ReportCardData ...
3
by: Geoff Tanaka | last post by:
Hi, I have created a DIB in C# and I am having a problem using it in a C++ DLL. Basically I have a C++ DLL which requires a DIB handle to be passed into it. I create the DIB using: IntPtr myDIB...
3
by: Alex J. | last post by:
I just started to learn C# (my background is in C++), and right now I study the sockets, TCP/IP etc... so, I found a usefull source code at:...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.