By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,375 Members | 3,030 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,375 IT Pros & Developers. It's quick & easy.

How to handle System.NullReferenceException??

P: 111
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

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

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

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

End If
XmlDocument = Nothing

Return MyGet

End Function

now can u tell me the solution...

thnks all...
Apr 25 '07 #1
Share this Question
Share on Google+
2 Replies

Expert 100+
P: 692

Put the whole code under

catch ex as Exception
''''''''''you can get here exception message ,source etc.

end Try
Apr 25 '07 #2

Expert 100+
P: 759
If DocumentName.Length == 0

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

Post your reply

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