473,797 Members | 3,174 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 2771
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
1845
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
1717
by: Terry Mulvany | last post by:
namespace CIBWeb { public class BasePage : System.Web.UI.Page { public BasePage() { } protected override void OnInit(EventArgs e) {
2
3106
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
3622
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
11900
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
1279
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
8912
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
9536
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
10468
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
10245
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
10205
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
7559
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
5458
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
5582
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3748
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2933
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.