![]() |
|
|
|||||||
![]() |
ASP Net - Help using Application object in ASP.NET! |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
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 |
|
|
|
|
#2 |
|
Posts: n/a
|
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> |
|
|
|
#3 |
|
Posts: n/a
|
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 |
|
|
|
#4 |
|
Posts: n/a
|
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> |
|
|
|
#5 |
|
Posts: n/a
|
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 |
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |