473,806 Members | 2,748 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

can't access: System.Web.Http Context.Current .Cache

A. I need to access: System.Web.Http Context.Current .Cache

but get this error:

"Object reference not set to an instance of the object"

B. System.Web.Http Context.Current .Cache is accessible outside of this
class.

I have listed the code below and the offending line of code is delimited by

//The next line breaks: "Object reference not set to an instance of
the object"

Thank you,

John Bickmore

+++++++++++++++ +++++++++++++++ +++
+++++++++++++++ +++++++++++++++ +++

using System;
using System.Threadin g;
using myclasses;

namespace mrFooter
{
public class mrFooter
{
public Thread myThread;

//Parameter(s) go here
string ySessionUser = "";
string yCookieUserEmai l = "";

public void Update(string xSessionUser)
{
// init values
ySessionUser = xSessionUser;

CookieUtil myCookie = new CookieUtil();
yCookieUserEmai l = myCookie.GetUse rEmail();

myThread=new Thread(new ThreadStart(Upd ateCache));
myThread.Start( );
}

private void UpdateCache()
{
string sUser = "";
bool Continue = true;

try
{
while ( Continue )
{
if ( ySessionUser == null || ySessionUser == String.Empty)
{
Continue = false;
}
else
{

if ( yCookieUserEmai l == ySessionUser )
{

//the next line breaks: "Object reference not set to an instance of the
object"
sUser = (string)System. Web.HttpContext .Current.Cache[ySessionUser];
//the previous line breaks: "Object reference not set to an instance of the
object"

Thread.Sleep(Sy stem.TimeSpan.F romMilliseconds (110000));
Continue = true;
}
else
{
Continue = false;
}
}
}//end while
}// end try
catch(Exception err)
{
Continue = false;
clsErrorsIO myError = new clsErrorsIO();
myError.errMess age = "Error while reading cache";
myError.errNumb er=0;
myError.errSour ceObject = "clsUpdateFoote r";
myError.errSour ceEvent = "Update";
myError.errSour ceMsg = err.Message.ToS tring();
myError.ErrorAd d();
}
finally
{
}
}
}//end of class: mrFooter
}//end of Namespace: clsUpdateFooter

Nov 19 '05 #1
3 2772
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@com cast.net>
wrote:
A. I need to access: System.Web.Http Context.Current .Cache

but get this error:

"Object reference not set to an instance of the object"


Nov 19 '05 #2
Thank you, http://www.odetocode.com/Articles/112.aspx is a good article,
thank you for your reply.

BTW "The 5 Stages Of Mocking" is great! My wife is Canadian, knows
everything about medicine and nothing about software, laughed too. She
wants to know if you sell t-shirts.
"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:6c******** *************** *********@4ax.c om...
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@com cast.net>
wrote:
A. I need to access: System.Web.Http Context.Current .Cache

but get this error:

"Object reference not set to an instance of the object"

Nov 19 '05 #3
Thanks :) - I don't have any t-shirts at the moment :)

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 19:29:46 -0600, "xzzy" <mr********@com cast.net>
wrote:
Thank you, http://www.odetocode.com/Articles/112.aspx is a good article,
thank you for your reply.

BTW "The 5 Stages Of Mocking" is great! My wife is Canadian, knows
everything about medicine and nothing about software, laughed too. She
wants to know if you sell t-shirts.
"Scott Allen" <sc***@nospam.o detocode.com> wrote in message
news:6c******* *************** **********@4ax. com...
The context is associated with a specific thread - if you throw
processing onto a second thread, the second thread won't have an
associated context.

See:
http://www.odetocode.com/Articles/112.aspx

--
Scott
http://www.OdeToCode.com/blogs/scott/

On Thu, 29 Sep 2005 12:58:23 -0600, "xzzy" <mr********@com cast.net>
wrote:
>A. I need to access: System.Web.Http Context.Current .Cache
>
> but get this error:
>
> "Object reference not set to an instance of the object"
>


Nov 19 '05 #4

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

Similar topics

4
1846
by: Al Cohen | last post by:
We've got a few methods that take a long time to complete. We're in the process of starting to launch these as separate threads, and having the web form refresh every few seconds to report the method's progress. Communication between "new" thread and web page is via the Session object. (Not rocket science so far.) The first problem that we ran into was that our methods could not see the Session object anymore once they were placed in a...
2
1718
by: Terry Mulvany | last post by:
namespace CIBWeb { public class BasePage : System.Web.UI.Page { public BasePage() { } protected override void OnInit(EventArgs e) {
2
3108
by: Steve W | last post by:
I have an ASP.NET app that calls into some VB.NET components. It passes in the current application's cache (HttpContext.Current.Cache). These VB.NET components also get called by a non-ASP.NET application (in this case a VB.NET windows service). I'd like to create something like the cache in this service to hold application-wide information (like database connection strings) and then pass that into the components. As a test, I tried...
17
3633
by: Joe | last post by:
Hello All; I can't access System.Web.HttpServerUtility from within a Class. I want to have access to MapPath. What I get are three options. They are: AspNetHostingPermission AspNetHostingPermissionAttributes AspNetHostingPermissionLevel
0
5020
by: bharathreddy | last post by:
Here I will given an example on how to access the session, application and querystring variables in an .cs class file. Using System.Web.HttpContext class. 1) For accesing session variables : System.Web.HttpContext.Current.Session 2) For accesing Application variables : System.Web.HttpContext.Current.Application 3) For accesing QueryString variables : System.Web.HttpContext.Current.Request.QueryString Here is a simple example where...
4
11904
by: msch-prv | last post by:
Hello. I am trying to use caching to populate a datalist. The select method of the associated objectdatasource calls up GetRecipePageByRecipeCatID() to request the proper data (I am using custom paging at SQL level so there is a paging idx as well). The code works fine when caching is edited out. Problem. The cache object is only created the first time around. When the dtl ia refreshed, th HttpContext.cache object always returns...
0
1281
by: =?Utf-8?B?TWFydGlu?= | last post by:
Hi I have a component (vb.net class project) which is used by both a web app and windows app. But it uses Web.HttpContext.Current.Cache , works fine in the web app but refuses to work in the windows app, even with all the correct references. Just gives and Null Reference error. What needs to be done to get Web.HttpContext.Current.Cache to work in the windows app environment? Any help would be appreciated :)
6
5190
by: =?Utf-8?B?emlubw==?= | last post by:
in asp.net 2, I load a dataset from the Cache object into a local object to use to perform processing. I had been using httpcontext.current.cache and what I noticed is sometime I'm not able to get the dataset out of the cache. the application is under heavy hits, and is set to email me on every error. and once or twice every month I get these error e-mail about this issue. why does the HTTPContext.Current.Cache call work sometimes, while...
3
8913
by: Madhur | last post by:
Hello I am delivering an asp.net 2.0 application to my customer. I need to know, If I need to check for the condition of HttpContext.Current to be null in my business logic. I have extensively used Cache and Session objects, and currently I assume HttpContext.Current object to be existent. Also, since I do not have this check, some of my unit test cases fail because there is no HttpContext for them.
0
9719
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
9599
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10624
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10371
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...
0
10111
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9193
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5684
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4330
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
3853
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.