Hello I am currently developing my masters project and am relativly new to C#
I am having a problem with my Cache. In settings.settin gs I have placed the following after my connection setting:
DefaultCacheDur ation_Day Int Application 1
DefaultCacheDur ation_Hours Int Application 0
DefaultCacheDur ation_Minutes Int Application 0
I then have a cache.cs: - using System;
-
using System.Collections;
-
using System.Collections.Generic;
-
using System.Web;
-
using System.Web.Caching;
-
using Forestry.SchoolLibrary.Properties;
-
-
namespace Forestry.SchoolLibrary.Impl
-
{
-
public class Cache
-
{
-
private static System.Web.Caching.Cache cache;
-
private static TimeSpan timeSpan = new TimeSpan(
-
Settings.Default.DefaultCacheDuration_Days,
-
Settings.Default.DefaultCacheDuration_Hours,
-
Settings.Default.DefaultCacheDuration_Minutes, 0);
-
-
static Cache()
-
{
-
cache = HttpContext.Current.Cache;
-
}
-
-
public static object Get(string cache_key)
-
{
-
return cache.Get(cache_key);
-
}
-
-
public static List<string> GetCacheKeys()
-
{
-
List<string> keys = new List<string>();
-
IDictionaryEnumerator ca = cache.GetEnumerator();
-
while (ca.MoveNext())
-
{
-
keys.Add(ca.Key.ToString());
-
}
-
return keys;
-
}
-
-
public static void Set(string cache_key, object cache_object)
-
{
-
Set(cache_key, cache_object, timeSpan);
-
}
-
-
public static void Set(string cache_key, object cache_object, DateTime expiration)
-
{
-
Set(cache_key, cache_object, expiration, CacheItemPriority.Normal);
-
}
-
-
public static void Set(string cache_key, object cache_object, TimeSpan expiration)
-
{
-
Set(cache_key, cache_object, expiration, CacheItemPriority.Normal);
-
}
-
-
public static void Set(string cache_key, object cache_object, DateTime expiration, CacheItemPriority priority)
-
{
-
cache.Insert(cache_key, cache_object, null, expiration, System.Web.Caching.Cache.NoSlidingExpiration, priority, null);
-
}
-
-
public static void Set(string cache_key, object cache_object, TimeSpan expiration, CacheItemPriority priority)
-
{
-
cache.Insert(cache_key, cache_object, null, System.Web.Caching.Cache.NoAbsoluteExpiration, expiration, priority, null);
-
}
-
-
public static void Delete(string cache_key)
-
{
-
if (Exists(cache_key))
-
cache.Remove(cache_key);
-
}
-
-
public static bool Exists(string cache_key)
-
{
-
if (cache[cache_key] != null)
-
return true;
-
else
-
return false;
-
}
-
-
public static void Flush()
-
{
-
foreach (string s in GetCacheKeys())
-
{
-
Delete(s);
-
}
-
}
-
}
-
}
My error message is An object reference is required for the non-static field, method, or property 'Forestry.Schoo lLibrary.Proper ties.Settings.D efaultCacheDura tion_Hours.get'
and this appears in my connection.cs which is as follows: - using System;
-
using System.Collections.Generic;
-
using System.Configuration;
-
using System.Linq;
-
using System.Data.Linq;
-
using System.Text;
-
using System.Xml;
-
using Forestry.SchoolLibrary.Domain;
-
using Forestry.SchoolLibrary.Properties;
-
-
namespace Forestry.SchoolLibrary.DataAccess.Impl
-
{
-
public class Connection
-
{
-
public SchoolDataContext GetContext()
-
{
-
string connString = "";
-
try
-
{
-
XmlDocument doc = new XmlDocument();
-
doc.Load("ConnectionStringToUse.xml");
-
-
XmlNodeList xnl = doc.GetElementsByTagName("environment");
-
XmlElement xe = (XmlElement)xnl[0];
-
-
switch (xe.InnerText.ToString().ToLower())
-
{
-
case "local":
-
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringLocal;
-
break;
-
-
case "development":
-
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringDevelopment;
-
break;
-
-
case "production":
-
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringProduction;
-
break;
-
-
default:
-
throw new Exception("No connection string defined in app.config!");
-
}
-
}
-
catch
-
{
-
connString = Settings.DefaultCacheDuration_Hours.SchoolConnectionStringLocal;
-
}
-
-
SchoolDataContext fdc = new SchoolDataContext(connString);
-
return fdc;
-
}
-
}
-
}
I'm not sure if I have provided all the relevant information, but if anyone could help me figure this out it would be greatly appreciated
many thanks
Rachel
1 8612 tlhintoq 3,525
Recognized Expert Specialist
In general terms:
Any object or method marked 'static' means you only have one of them.
You cannot create multiple instances of such a method or object.
Any object or method NOT marked 'static' means you *have* to make an instance of it in order to use it.
Thus you cannot call a static method like you would a non-static method, and vice-versa
When you run this in debug, and Visual Studio stops on a line and highlights for this error... that should show you where the error occurs. At that point you are trying to get an *instance* of something that has been labeled static. And you can't do that. That's what the error is saying: You have a field, or method or property that isn't static ("for the non-static feild, property or method"), that needs a instance of an object
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: FredC |
last post by:
OS Name Microsoft Windows XP Professional
Version 5.1.2600 Service Pack 2 Build 2600
Total Physical Memory 1,024.00 MB
MDE 2003 Version 7.1.3008
..NET Framework 1.1 Version 1.1.4322 SP1
Microsoft Visual C# .NET 69462-335-0000007-18707
Crystal Reports for Visual Studio .NET AAP50-GS0000S-WCK00C3
|
by: Bucko |
last post by:
Hi guys,
this may be an easy for someone...
I have a situation like below. The "str" string variable (and any other
variable that VS.net declares normally in this space) can be used fine
in the Page_Load function, but not my own function, "datareaderconvert"
Anyone know why? Here's what it looks like:
|
by: Tee |
last post by:
Hi,
I having a problem with my asp.net project.
The project work fine on my own PC, but when I upload it to the server, I
got the following error :
Object reference not set to an instance of an object
I have try to search for the solution using this error message, and I found
that a lot of other people have the same problem as the...
|
by: Mark Wilson |
last post by:
For some reason I am getting this error even though (as you can see from the
code in the Initialize Component procedure) the object reference has been
established... I am at my wit's end.. Thanks for any advice...
--------------------
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
|
by: Microsoft |
last post by:
When I try this in my code I alwas get an errormessage: "Object reference
not set to an instance of an object"
Dim g As System.Drawing.Graphics
g.DrawString("Test", New Font("Arial", 12, FontStyle.Bold), Brushes.Black,
0, 0)
Why is this?
Marc
| |
by: Mike Clark |
last post by:
I have a webservice that works great on localhost, but as soon as I promote
to a network server I get an exception that doesn't tell me much. There's
some implementation details in this exception chain, but here's what it looks
like:
<pre>System.Web.Services.Protocols.SoapException: Server was unable to
process request. --> Object...
|
by: marylipscomb |
last post by:
I don't understand why this isn't working. I am trying to have the button create a fill a table I guess when they click a button. I am having so much trouble with this.
The table adapter is called CompaniesTableAdapter and the dataset is called GetActiveCompanies.
Protected Sub btnCompanyLookup_Click(ByVal sender As Object, ByVal e As...
|
by: cppquester |
last post by:
I have a data set
MMSDataAccess
with:
public partial class MMSDataSet : System.Data.DataSet {
...
private TB_ACTHEATDATADataTable tableTB_ACTHEATDATA;
...
|
by: asm23 |
last post by:
Hi,I need some help to clarify the warning "initial value of reference
to non-const must be an lvalue".
I'm searching in this groups to find someone has the same situation like
me. I found in the Post:...
|
by: cday119 |
last post by:
Reference to a non-shared member requires an object reference in the declarations on "Form1.tabSearch.". Anyone know why this is happening?
Public Function getArgs(ByVal Op As String, ByVal OpeningQuote As String, ByVal ClosingQuote As String, Optional ByVal controls As Windows.Forms.Control.ControlCollection = Form1.tabSearch.Controls)...
|
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...
| |
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. ...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| | |