473,396 Members | 1,914 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,396 software developers and data experts.

'System.Web.Caching.Cache' is a 'type', which is not valid in the given context ??

What's wrong with this:

Error 3 'System.Web.Caching.Cache' is a 'type', which is not valid
in the given context

public List<AssetSummaryGetAssetSummary()
{
return
(List<AssetSummary>)System.Web.Caching.Cache("asse tSummary");
}
Is it telling me that I can't get a generic list out of the Cache - if
so why does it let me put it in in the first place?

OR - Will it not let me cast the Cache("assetSummary") as a generic
list?
Feb 23 '07 #1
4 15080
Hi,

Harry Haller wrote:
What's wrong with this:

Error 3 'System.Web.Caching.Cache' is a 'type', which is not valid
in the given context

public List<AssetSummaryGetAssetSummary()
{
return
(List<AssetSummary>)System.Web.Caching.Cache("asse tSummary");
}
Is it telling me that I can't get a generic list out of the Cache - if
so why does it let me put it in in the first place?

OR - Will it not let me cast the Cache("assetSummary") as a generic
list?
Two issues:

1) To access an item in the Cache in C#, you use '[]', not '()' like in
VB.NET

2) You want to use the Cache property, *not* the type
System.Web.Caching.Cache. So, if you're in a Page, simply type:

public List<AssetSummaryGetAssetSummary()
{
return (List<AssetSummary>) Cache["assetSummary"];
}

If you're not in a Page, but for example in an ASHX custom handler, you
can also access the Cache using the HttpContext:

public List<AssetSummaryGetAssetSummary()
{
return (List<AssetSummary>)
HttpContext.Current.Cache["assetSummary"];
}

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 23 '07 #2
On 23 Feb, 09:12, "Laurent Bugnion [MVP]" <galasoft...@bluewin.ch>
wrote:
Hi,

Harry Haller wrote:
What's wrong with this:
Error 3 'System.Web.Caching.Cache' is a 'type', which is not valid
in the given context
public List<AssetSummaryGetAssetSummary()
{
return
(List<AssetSummary>)System.Web.Caching.Cache("asse tSummary");
}

If you're not in a Page, but for example in an ASHX custom handler, you
can also access the Cache using the HttpContext:

public List<AssetSummaryGetAssetSummary()
{
return (List<AssetSummary>)
HttpContext.Current.Cache["assetSummary"];

}
Thanks Laurent, that was what was puzzling me. I got the same error
whether I used Cache["..."] or Cache("..."). My real problem was that
I couldn't figure out what namespace to use.

Is there a way to quickly figure out which namespaces one needs to
include? for instance, when using the Cache in code which resides in
the App_Code directory?

(From the original author)

Feb 23 '07 #3
Howdy,

Yes, VS2005 has built-in context hint feature. In class code write:

HttpContext

notice a small red bar under last two letters, hover around it and then you
shall see an expandable list with options to automatically add 'using'
directive with correct namespace (of if there are many classes with the same
name in different namespaces you'll see them all) or use fully qualified
namespace.

Hope this helps

--
Milosz
"mark4asp" wrote:
On 23 Feb, 09:12, "Laurent Bugnion [MVP]" <galasoft...@bluewin.ch>
wrote:
Hi,

Harry Haller wrote:
What's wrong with this:
Error 3 'System.Web.Caching.Cache' is a 'type', which is not valid
in the given context
public List<AssetSummaryGetAssetSummary()
{
return
(List<AssetSummary>)System.Web.Caching.Cache("asse tSummary");
}
If you're not in a Page, but for example in an ASHX custom handler, you
can also access the Cache using the HttpContext:

public List<AssetSummaryGetAssetSummary()
{
return (List<AssetSummary>)
HttpContext.Current.Cache["assetSummary"];

}

Thanks Laurent, that was what was puzzling me. I got the same error
whether I used Cache["..."] or Cache("..."). My real problem was that
I couldn't figure out what namespace to use.

Is there a way to quickly figure out which namespaces one needs to
include? for instance, when using the Cache in code which resides in
the App_Code directory?

(From the original author)

Feb 23 '07 #4
Hi,

mark4asp wrote:
Thanks Laurent, that was what was puzzling me. I got the same error
whether I used Cache["..."] or Cache("..."). My real problem was that
I couldn't figure out what namespace to use.

Is there a way to quickly figure out which namespaces one needs to
include? for instance, when using the Cache in code which resides in
the App_Code directory?

(From the original author)
Additionally to Milosz suggestion (Intellisense), MSDN is your best bet
for information about classes. I like to search on Google, very often
the first page found is from MSDN, I found it faster than to open MSDN
and type the search there. Additionally, with a little experience, you
know the syntax to put MSDN on top of the Google search, for example:

"Cache property"

First link: HttpContext.Cache
Second link: Page.Cache

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Feb 23 '07 #5

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

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
12
by: R | last post by:
Hello everybody. I'm writing my own Content System in PHP5. I've written so far main classes for handling DB connections, XML, XForms and Sessions. But I've got problem with one thing - it's...
9
by: Just D. | last post by:
All, Did anybody see this strange effect? The web application is written in C#, ASP.NET, SQL, T-SQL, etc. A pretty usual stuff, complicated enough, but works fine until... Here is a question....
6
by: Hypo | last post by:
Im relatilvly new to a web programming in general, and here's the situation i have: I have a default page with dynamic content, and one button with onclick code something like this: { // do...
3
by: Janaka | last post by:
Hi All, I'm having a problem with Page Output caching on a page that contains a DataGrid. Basically the page pulls up some data for sales information from the DB. Some of this has to be...
2
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...
0
by: thinkfr33ly | last post by:
Is there any way, either via an ASHX file or lines in a code behind, to enable output caching for an HTTP Handler? This is driving me nuts. Nothing I try works. I've tried this in the...
2
by: Cramer | last post by:
I'm creating a custom handler that does not extend Page (only implements IHttpHandler) - and I would like for its output to be cached to improve runtime performance. I would like to leverage...
2
by: Ken Fine | last post by:
I have a question about ASP.NET output caching. I want to use screen scraping as a temporary hack to pull in some complex Classic ASP-rendered content into some ASP.NET pages: protected String...
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
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
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...
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,...
0
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...
0
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...
0
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...
0
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,...

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.