473,732 Members | 2,171 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Object reference not set to an instance of an oject

We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.

When trying to access a page that needs the class module I get an error on
web site:

Object reference not set to an instance of an object

Here is where the error is:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

Under the stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
and a bunch of other code :)

Engine is the name of the dll and yes it is being referenced in the project.

Any help would be great!!

Thanks,
Adam
Nov 19 '05 #1
3 4227
You have several object references in that statement. Your job is to figure
out which one is Nothing, and why. Let's identify them:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

"Engine" is the first possible object reference. However, as you say it's
the name of a VB.Net DLL, it would have to be a NameSpace reference, which
is not an object, but a perfectly legal part of an object reference.

"Globals" would be the second possible object reference. As you are calling
a method via "Globals," I would say that this is very probably indeed an
object (an instance of a class) or a class. If it is not an instance of a
class, you could not call a method from it unless that method was a Shared
(static) method. Otherwise you would indeed get a NullReferenceEx ception,
because you didn't have an instance of the Globals class. The only way
"Globals" could be an instance of a class is if "Engine" was either an
instance of a class or a class with a Shared "Globals" instance in it. But
as you have identified "Engine" as a NameSpace, "Globals" would not be an
instance of a class, but an uninstantiated class. So, if "GetRegions ()" is
not a shared method, there is your exception.

But let's imagine that (it is perfectly possible) "GetRegions ()" is a Shared
method, and that "Globals" is a class that is not instantiated, in the
"Engine" namespace. In that case, we have 1 other possibility to examine. If
"Me.State" is Nothing (null), this would then throw the
NullReferenceEx ception. String.Empty is an empty string (""), so it would
not.

So, you should now have all the information you need to determine the cause
of your exception.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Adam" <Ad**@discussio ns.microsoft.co m> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.

When trying to access a page that needs the class module I get an error on
web site:

Object reference not set to an instance of an object

Here is where the error is:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

Under the stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
and a bunch of other code :)

Engine is the name of the dll and yes it is being referenced in the
project.

Any help would be great!!

Thanks,
Adam

Nov 19 '05 #2
Thank you for your reply.. Very informative.

The Engine is a C#.dll, Global is the global.cs file and GetRegion is :
public static void GetRegions(Syst em.Web.UI.WebCo ntrols.DropDown List
regionList, string selectedValue)

I will look at the other information you supplied and you know what we come
up with.

Thanks,
Adam

"Kevin Spencer" wrote:
You have several object references in that statement. Your job is to figure
out which one is Nothing, and why. Let's identify them:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

"Engine" is the first possible object reference. However, as you say it's
the name of a VB.Net DLL, it would have to be a NameSpace reference, which
is not an object, but a perfectly legal part of an object reference.

"Globals" would be the second possible object reference. As you are calling
a method via "Globals," I would say that this is very probably indeed an
object (an instance of a class) or a class. If it is not an instance of a
class, you could not call a method from it unless that method was a Shared
(static) method. Otherwise you would indeed get a NullReferenceEx ception,
because you didn't have an instance of the Globals class. The only way
"Globals" could be an instance of a class is if "Engine" was either an
instance of a class or a class with a Shared "Globals" instance in it. But
as you have identified "Engine" as a NameSpace, "Globals" would not be an
instance of a class, but an uninstantiated class. So, if "GetRegions ()" is
not a shared method, there is your exception.

But let's imagine that (it is perfectly possible) "GetRegions ()" is a Shared
method, and that "Globals" is a class that is not instantiated, in the
"Engine" namespace. In that case, we have 1 other possibility to examine. If
"Me.State" is Nothing (null), this would then throw the
NullReferenceEx ception. String.Empty is an empty string (""), so it would
not.

So, you should now have all the information you need to determine the cause
of your exception.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Adam" <Ad**@discussio ns.microsoft.co m> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
We have a web site that uses .vb for the web pages and .cs for a class
module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It does
work with .NET 1.1.

When trying to access a page that needs the class module I get an error on
web site:

Object reference not set to an instance of an object

Here is where the error is:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

Under the stack Trace:
[NullReferenceEx ception: Object reference not set to an instance of an
object.]
and a bunch of other code :)

Engine is the name of the dll and yes it is being referenced in the
project.

Any help would be great!!

Thanks,
Adam


Nov 19 '05 #3
Hi Adam,

First, let me make sure you understand the difference between a DLL, a
NameSpace, and a Class, since you like to toss references to DLLs about, and
DLLs are not part of a running application. A DLL is a file. It contains
code that is loaded into System memory when the application starts. It is
not directly used by the application. The code (classes, etc) from the DLL
is loaded into memory, and from there you have the actual NameSpaces,
classes, etc., that your application uses. At this point it is best to think
of these things as objects or things, rather than as code, as that is how
they behave.

A NameSpace is a logical container, or identifier. You might think of a
NameSpace as, for example, a country, or a state in a country. It has a
name, and contains other things. But other than that, it has no
functionality. It is used by an object-oriented program to uniquely identify
the things inside it. For example, there is a city in Pennsylvania named
"Philadelph ia." There is also a city named "Philadelph ia" in Tennessee. So,
if I were to tell you that I was going to travel to Philadelpphia, you could
not logically determine what city I was going to. The name of the city would
be ambiguous. But if I were to tell you that I was going to Philadelphia,
Pennsylvania, you would know for sure which Philadelphia I was going to be
in.

A class is like a business in a city. It has functionality. It does things.
It has properties, such as Employees, a number of products that it produces,
it's income, profit, etc. The class is identified, as a business is
identified, by its address. So, let's say you were in Philadelphia,
Pennsylvania, and you wanted to go to City Hall to obtain a license. City
Hall is like a business, but I'm using a reference to a business for which
there is only one instance in any city as an example to make things simpler
and clearer. So, you're in Philadelphia, Pennsylvania and you're going to go
to City Hall. You want your friend to meet you there, so you tell her "Meet
me at City Hall." Of course, there is a City Hall in every city, but you're
already in a city, so you don't have to tell her "I'm going to City Hall,
Phildelphia, Pennsylvania." You just have to say "City Hall." But what if
you were outside a city, in a county somewhere in the same state? You would
then have to say "I'm going to the Philadelphia City Hall." Or, if you were
outside the country, and you wanted her to meet you in City Hall in
Philadelphia, Pennsylvania, you would have to use the full address. In fact,
you might also have to use the country name. So, in this illustration,
"Pennsylvan ia" and "Philadelph ia" are like NameSpaces. They are simply used
for addressing, or identifying. If you had an application with a NameSpace
of "Pennsylvan ia" containing a NameSpace of "Philadelph ia," and in that
NameSpace a class named "CityHall," you would refer to it as
"Pennsylvania.P hiladelphia.Cit yHall."

And .Net has one more twist in store for you. The same NameSpace can exist
in multiple DLLs. Although this is generally not the right way to do things,
there are situations in which it IS the right way to do things, for purposes
of optimization. That is, when you load a DLL, you load the ENTIRE DLL into
memory, into what is called "the heap." So, while some classes might all
logically seem to belong in the same parent NameSpace, there can be
situations in which certain types of apps might not need a bunch of them,
and it would therefore waste memory to load them at run-time. I have seen
this in several (nut thankfully not many) of the .Net CLR dlls. Still, it is
important to remember, and not assume that because 2 classes or NameSpaces
are in different DLLs that they are not in the same parent NameSpace. Using
Geography again as an illustration, think of the U.S., in which 49 states
are in the same continent. But of course, there are 50 states. Hawaii is not
in the North American continent. But it is in the "NameSpace" of the U.S.

Finally, a Class is a NameSpace, but it is not quite the same as a
NameSpace. That is, a Class is a logical container, which can contain other
Classes, structures, enumerations, but also Fields, Properties, Constants,
Methods, etc. A NameSpace doesn't have to be a Class. Unless it is defined
as a Class, it is not a Class. But a Class is always a NameSpace. In other
words, a Class is a special type of NameSpace, which has all of the
object-oriented properties of a Class.

Okay, you've got a C# DLL, and the name of it, I will guess, is
"Engine.Dll ." Now, C# is different from VB.Net in the way that it compiles
projects. In VB.Net, the default NameSpace for a DLL is the name of the DLL.
You can change it, but it is assigned automatically as the NameSpace unless
you do. In C#, you must assign a NameSpace yourself. So, the "Engine.DLL "
could contain any NameSpace as its top-level container. You need to find out
what it is if you want to use it in your app. If using Visual Studio.Net,
the Class View Pane will show you, as will the Object Browser (and of
course, Intellisense).

Your app also uses a Global.asax source code file. This compiles to a class
called "Global," which resides in your app's DLL's root NameSpace, whatever
it is. Note that this NameSpace will (almost certainly) be different than
the Engine.DLL's root NameSpace. However, I'm not sure if that is what
you're referring to, as you mentioned a source code file named "global.cs. "
But, if you want to learn more about the Global class that is compiled from
the global.asax file, see http://odetocode.com/Articles/89.aspx.

For now, I will assume that the "global.cs" source code file is a different
source code file. Note that I have not referred to any class yet, as a
source code file is NOT part of your app, but is used to compile your app.
In fact, the name of the source code file doesn't necessarily have any
relationship with any of the classes contained therein, and there may be
more than one class, enumeration, and/or structure defined in it.

Since you didn't mention the name of the class that contains the
"GetRegions ()" method (only the name of the source code file), I can't even
assume that it is indeed contained in a class named "Globals." For now, I
will make that working assumption. Assuming that it is, you need to identify
the NameSpace of the class in which it resides. It is (almost certainly) not
in the "Engine" NameSpace.

Hopefully, this should help clear things up. Remember:

DLLs are not part of your application, which resides in memory at run-time
A DLL can contain more than one NameSpace
NameSpaces are logical containers used to identify the "address" of the
items inside them
NameSpaces can reside in more than one DLL
NameSpaces can be contained in other NameSpaces
Classes reside in NameSpaces
Classes ARE NameSpaces, but a special type of NameSpace
Source Code files are not part of your application, but used to create it
A Source Code file can contain multiple NameSpaces and Classes
A Property, Field, or Method is uniquely identified by its NameSpace
hierarchy

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Adam" <Ad**@discussio ns.microsoft.co m> wrote in message
news:7E******** *************** ***********@mic rosoft.com...
Thank you for your reply.. Very informative.

The Engine is a C#.dll, Global is the global.cs file and GetRegion is :
public static void GetRegions(Syst em.Web.UI.WebCo ntrols.DropDown List
regionList, string selectedValue)

I will look at the other information you supplied and you know what we
come
up with.

Thanks,
Adam

"Kevin Spencer" wrote:
You have several object references in that statement. Your job is to
figure
out which one is Nothing, and why. Let's identify them:

Engine.Globals. GetRegions(Me.S tate, String.Empty)

"Engine" is the first possible object reference. However, as you say it's
the name of a VB.Net DLL, it would have to be a NameSpace reference,
which
is not an object, but a perfectly legal part of an object reference.

"Globals" would be the second possible object reference. As you are
calling
a method via "Globals," I would say that this is very probably indeed an
object (an instance of a class) or a class. If it is not an instance of a
class, you could not call a method from it unless that method was a
Shared
(static) method. Otherwise you would indeed get a NullReferenceEx ception,
because you didn't have an instance of the Globals class. The only way
"Globals" could be an instance of a class is if "Engine" was either an
instance of a class or a class with a Shared "Globals" instance in it.
But
as you have identified "Engine" as a NameSpace, "Globals" would not be an
instance of a class, but an uninstantiated class. So, if "GetRegions ()"
is
not a shared method, there is your exception.

But let's imagine that (it is perfectly possible) "GetRegions ()" is a
Shared
method, and that "Globals" is a class that is not instantiated, in the
"Engine" namespace. In that case, we have 1 other possibility to examine.
If
"Me.State" is Nothing (null), this would then throw the
NullReferenceEx ception. String.Empty is an empty string (""), so it would
not.

So, you should now have all the information you need to determine the
cause
of your exception.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.

"Adam" <Ad**@discussio ns.microsoft.co m> wrote in message
news:9B******** *************** ***********@mic rosoft.com...
> We have a web site that uses .vb for the web pages and .cs for a class
> module. We are getting the error in .NET 2.0 and VS 2005 beta 2. It
> does
> work with .NET 1.1.
>
> When trying to access a page that needs the class module I get an error
> on
> web site:
>
> Object reference not set to an instance of an object
>
> Here is where the error is:
>
> Engine.Globals. GetRegions(Me.S tate, String.Empty)
>
> Under the stack Trace:
> [NullReferenceEx ception: Object reference not set to an instance of an
> object.]
> and a bunch of other code :)
>
> Engine is the name of the dll and yes it is being referenced in the
> project.
>
> Any help would be great!!
>
> Thanks,
> Adam


Nov 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1217
by: ElanKathir | last post by:
Hi See this, Public Class Elan Public variable as Interger Public Sub Function1() ---------- ------ End Sub
6
15441
by: Darren Linsley | last post by:
I know this might seem like a dumb question, but how do you test that an object exists. Maybe i should explain a little. I have a variable that points to an object. Now if that oject is released, how can i test my variable to see if the object it was pointing at, still exists? Please help!!
4
8060
by: stand__sure | last post by:
This has bugged me for some time. Is there any "behind the scenes" difference between the following two snippets? Dim obj1 As Object = New Oject() {} Dim obj2 As Object = New Object(-1) {} Thanks!
6
2238
by: Rufnex | last post by:
Hi, is there a delete for a object inside the constructor, while i init it? i will try something like that: var obj = function(a) { if (!a) delete this; this.a = a; }
12
5555
by: Andrew Poulos | last post by:
With the following code I can't understand why this.num keeps incrementing each time I create a new instance of Foo. For each instance I'm expecting this.num to alert as 1 but keeps incrementing. Foo = function(type) { this.num = 0; this.type = type this.trigger(); } Foo.prototype.trigger = function() {
73
4486
by: Water Cooler v2 | last post by:
I am new to PHP, just one day new. But I am otherwise a seasoned programmer on many other languages like C, VB 6, C#, VB.NET, Win32 platform and have some tiny bit experience in MFC, C++, Python. All the tutorials I read so far about PHP contain procedural examples. I haven't yet come accross a tutorial on the object oriented PHP. Could someone point me to one?
6
2478
by: Shailen Sukul | last post by:
Observed a weird behaviour with object references. See code listing below: using System; using System.Collections.Generic; using System.Text; namespace PointerExceptionTest { /*
2
2654
by: Ralph | last post by:
Hi I don't understand why it's not working: function schedule(imTop){ this.tdImagesTop = imTop; } schedule.prototype.selectEl = function() { alert(this.tdImagesTop);
275
12337
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
8946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9235
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6735
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6031
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4550
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4809
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3261
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.