NullReferenceException with shared members

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Michael.Thomlinson@gmail.com

    #1

    NullReferenceException with shared members

    Hello fellow coders,

    I have run into an issue that is otherwise painfull for my brain to
    think about at this point so i turn to you guys for input.

    Scenario.

    For my application i have chosen to make my own "Environmen t"
    This environment contains Variables and Methods that are Shared.

    For Example

    'Properties

    Public Shared Property MyObject as MyObject
    Get~~~~
    Set~~~~
    End Property

    Now i have basicly implemented 2 of these environment classes. one
    contains native .NET elements (SqlConnection to be specific) and the
    other one can be seen in the Example above. The one that is causing me
    problems is the environment as seen above and it contains an Object
    that i have defined.

    The working one i have implemented like this....

    Dim MyConnection as SqlConnection
    MyConnection = Stuff
    theEnvironment. DbConnection = MyConnection

    The broken one i have implemented like this....

    Dim MyObj as MyObject '<-- i created this objects class
    MyObj = Stuff
    theEnvironment. MyObject = MyObj

    The actual meaning of what im doing is a Login Screen that Takes the
    Users credentials and puts it into the environment so that other parts
    of the application can access it.

    The Environment contains

    DbConnection
    UserObject

    The UserObject contains a constructor with NON shared properties one of
    which is another Object.
    -----------------------------------------------------------------------------

    I hope i have given enough information to outline the problem

  • Michael.Thomlinson@gmail.com

    #2
    Re: NullReferenceEx ception with shared members

    Okay so there is no need to reply as i have just solved my problem...

    Cause
    theEnvironment. Object was not instantiated..

    Solution
    the member declaration was altered from
    Dim mObject as MyObject
    to
    Dim mObject as NEW MyObject

    Rofl :P

    Comment

    • Robinson

      #3
      Re: NullReferenceEx ception with shared members

      the member declaration was altered from
      Dim mObject as MyObject
      to
      Dim mObject as NEW MyObject
      >
      Rofl :P


      The number of times I've done
      that........... ............... ............... .....


      Comment

      Working...