473,387 Members | 1,582 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help using Application object in ASP.NET!

I have created a class that communicates with an external program using
a single socket connection. This socket connection is already
thread-safe, so multiple requests to the socket can be made at the same
time.

I am trying to set this up as a global object in an ASP.NET web server
running IIS 5.0, but I'm having a problem with that.

In the Global.asax.cs file, I have added the following reference:
CMyClass _theGlobalObjectOfMyClass;
Then in the Application_Start() routine, I added the following code:
_theGlobalObjectOfMyClass = new CMyClass();
Finally, on one of the pages in question I added the following code:

CMyClass _localReference = (CMyClass)
Application["_theGlobalObjectOfMyClass"];
When I try to load the page in question, I get the following error:
System.NullReferenceException: Object reference not set to an instance
of an object.

I have tried restarting IIS by going on the command line and using the
"iisreset", which tells me that the app is restarted successfully, but
nothing changes when I try to access the page. It's like the global
object is not there?

Anyways, if someone could point out what I'm doing wrong that would be
appreciated. One thing - the object in question is actually being
compiled as a separate DLL and linked into the web project in question
as a reference. Would it make a difference if I was not doing that?

Thanks!

Nov 19 '05 #1
4 1133
I would guess that your object is not marked as serializable? Try adding the
[Serializable()] attribute to your class.

--
Ian
"js******@gmail.com" wrote:
I have created a class that communicates with an external program using
a single socket connection. This socket connection is already
thread-safe, so multiple requests to the socket can be made at the same
time.

I am trying to set this up as a global object in an ASP.NET web server
running IIS 5.0, but I'm having a problem with that.

In the Global.asax.cs file, I have added the following reference:
CMyClass _theGlobalObjectOfMyClass;
Then in the Application_Start() routine, I added the following code:
_theGlobalObjectOfMyClass = new CMyClass();
Finally, on one of the pages in question I added the following code:

CMyClass _localReference = (CMyClass)
Application["_theGlobalObjectOfMyClass"];
When I try to load the page in question, I get the following error:
System.NullReferenceException: Object reference not set to an instance
of an object.

I have tried restarting IIS by going on the command line and using the
"iisreset", which tells me that the app is restarted successfully, but
nothing changes when I try to access the page. It's like the global
object is not there?

Anyways, if someone could point out what I'm doing wrong that would be
appreciated. One thing - the object in question is actually being
compiled as a separate DLL and linked into the web project in question
as a reference. Would it make a difference if I was not doing that?

Thanks!

Nov 19 '05 #2
I tried that by adding the [Serializable()] tag right above the class
declaration, but it didn't make any difference. Not sure if there was
anything else I was supposed to do?

To be honest, I don't know too much about serialization or why it would
be important in this case - can anybody help out on that?

Thanks...

Nov 19 '05 #3
You may have to mark any other custom classes that your main class uses as
serializable as well.

Serialization simply extracts the object and its values into XML, then the
deserialization recreates the object and sets the values back so you can
access them.

--
Ian
"js******@gmail.com" wrote:
I tried that by adding the [Serializable()] tag right above the class
declaration, but it didn't make any difference. Not sure if there was
anything else I was supposed to do?

To be honest, I don't know too much about serialization or why it would
be important in this case - can anybody help out on that?

Thanks...

Nov 19 '05 #4
I figured out a way to do what I want... by creating a static member
variable in Global.asax.cs like so:

public static CMyClass _theGlobalObjectOfMyClass = new CMyClass();

I was able to successfully call it from a web-page using:

Global._theGlobalObjectOfMyClass.SomeFunction();

and it worked.

Can anybody point out if there are problems with this approach that I
am not considering? This object has events that fire when a message is
received from a socket connection - would using a static class result
in problems with that?

Nov 19 '05 #5

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

Similar topics

5
by: The Roys | last post by:
Hi Im doing something wrong in quitting the Word.Application in my VB program. I have General Declarations Dim AppWord As Word.Application Form_Load() Set AppWord =...
5
by: Ken Varn | last post by:
I have a named mutex object that is accessed by both an asp.net application and a Windows executable .net application. The Windows executable runs under the administrator logon, while the asp.net...
0
by: Julia | last post by:
I need help with architecture design,please: I have a server which constantly downloading messages from the internet and store them inside a data base. the server have two administrators...
3
by: Kris van der Mast | last post by:
Hi, I've created a little site for my sports club. In the root folder there are pages that are viewable by every anonymous user but at a certain subfolder my administration pages should be...
3
by: Julia | last post by:
I need help with architecture design,please: I have a server which constantly downloading messages from the internet and store them inside a data base. the server have two administrators...
6
by: Guy Thornton | last post by:
I have an application in asp.net using vb. The asp.net portion of this application is mainly the user interface. The UI has references made to our business logic layer. And the business logic...
0
by: gunimpi | last post by:
http://www.vbforums.com/showthread.php?p=2745431#post2745431 ******************************************************** VB6 OR VBA & Webbrowser DOM Tiny $50 Mini Project Programmer help wanted...
5
by: althafexcel | last post by:
hi everyone Im trying to include an external js in my aspx page under the head tag, it doesn't load or it displays an object expected error whenver the function from the .js is called. Actually...
9
by: Ringo | last post by:
the LeafProject http://www.leafproject.org has a DLL for Face recognition. it is written in C++ but they interface to it from Lisp. I want to interface to it from C#. Their Lisp definitions looks...
4
by: Dave | last post by:
I have a global.asax file with Application_Start defined and create some static data there and in another module used in the asp.net application and I realize that static data is shared amongst...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.