NullReferenceException with shared members

  • Thread starter Michael.Thomlinson
  • Start date
M

Michael.Thomlinson

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 "Environment"
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.
 
M

Michael.Thomlinson

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
 
R

Robinson

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..............................................
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top