none
VB.net public class having shared method getting intermittent Object reference not found error RRS feed

  • Question

  • I am newbie to vb.net world. We have a class library written having public class having all of its variable and properties are Shared. We are facing issue for intermittent error 'Object reference not set to an instance of an object. at SQLDataAccess.ErrorCodes.get_TryCount() .....'

    Imports System.Xml
    
    Public Class ErrorCodes 
    
    Private Shared tryCnt As Integer = -2
    
    Public Shared Property TryCount() As Integer 
    
    Get 
    If tryCnt = -2 Then 
    Dim m_nodelist As XmlNodeList m_nodelist = XMLDOC.SelectNodes("/xml/TryCount") 
    Integer.TryParse(m_nodelist(0).FirstChild.Value, tryCnt) End If 
    Return tryCnt 
    End Get 
    
    Set(ByVal value As Integer) 
    tryCnt = value 
    End Set 
    End Property
    
    End Class 
    

    Chances of having this issue is very rare in non prod however in prod we getting almost 8-10 in week time. Any pointers. 


    Thursday, September 28, 2017 7:54 AM

All replies

  • I am newbie to vb.net world. We have a class library written having public class having all of its variable and properties are Shared.

    That makes you a newbie in Object Oriented concepts too. An object should not have variables and properties Shared, as it defeats the principle concepts of Encapsulation.

    http://www.informit.com/articles/article.aspx?p=25857&seqNum=3

     <copied>                

    Encapsulation in VB.NET

    Encapsulation is the exposure of properties and methods of an object while hiding the actual implementation from the outside world. In other words, the object is treated as a black box—developers who use the object should have no need to understand how it actually works.

    <end>

     

    The object should protect itself from outside access to internal variables by using public properties. 

    https://www.dotnetperls.com/property-vbnet

    If the solution is poorly written, then one can except unexpected things to happen.

    Thursday, September 28, 2017 11:41 AM
  • Please reformat your code block so we can actually read your code.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Thursday, September 28, 2017 11:44 AM
    Moderator