Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Help using Application object in ASP.NET!

 
Thread Tools Search this Thread
Old 08-10-2005, 09:06 PM   #1
Default 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!



jsever05@gmail.com
  Reply With Quote
Old 08-10-2005, 10:02 PM   #2
=?Utf-8?B?RU5JWklO?= .enizin.net>
 
Posts: n/a
Default RE: Help using Application object in ASP.NET!
I would guess that your object is not marked as serializable? Try adding the
[Serializable()] attribute to your class.

--
Ian


"" 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!
>
>



=?Utf-8?B?RU5JWklO?= .enizin.net>
  Reply With Quote
Old 08-10-2005, 10:20 PM   #3
jsever05@gmail.com
 
Posts: n/a
Default Re: Help using Application object in ASP.NET!
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...



jsever05@gmail.com
  Reply With Quote
Old 08-10-2005, 10:32 PM   #4
=?Utf-8?B?RU5JWklO?= .enizin.net>
 
Posts: n/a
Default Re: Help using Application object in ASP.NET!
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


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



=?Utf-8?B?RU5JWklO?= .enizin.net>
  Reply With Quote
Old 08-10-2005, 10:37 PM   #5
jsever05@gmail.com
 
Posts: n/a
Default Re: Help using Application object in ASP.NET!
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?



jsever05@gmail.com
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
COM object in asp.net fluoronator Software 1 03-04-2008 07:48 PM
ASP.NET 2.0 application does not run in WIN2k3 johnfraj Software 0 04-19-2007 08:27 AM
Unable to create ASP.NET application SHARP END Software 0 04-04-2007 10:54 PM
ASP.NET with User Interface Process Application Block robinp Software 0 03-05-2007 10:01 AM
ASP.NET application not working yogesh.sind Hardware 0 10-03-2006 09:55 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46