473,387 Members | 3,033 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,387 software developers and data experts.

An object reference is required for the nonstatic field, method or

I am getting the above error with this Class Library code:

namespace ClassLibrary1
{
public class Class1
{
private string FoundPathKey;
public string LastError
{
get { return FoundPathKey; }
}
public static string Read(string path, string key)
{
string keyval = "";
try
{
FoundPathKey = "";
keyval = Microsoft.Win32.Registry.GetValue(path, key,
"Missing").ToString();
if (keyval == "Missing")
{
throw new Exception("Either the path <" + path + "OR
the key <" + key + "does not exist");
}
}
catch (Exception MyExcep)
{
FoundPathKey = MyExcep.Message.ToString();
}
return keyval;
}
}
}

on the two lines where I assign a value to FoundPathKey and I do not have a
clue why.

Could somene please point out what it is that I am missing?

Thank you.
May 25 '07 #1
1 1974
FoundPathKey does not have a static modifier, while function Read has.
You can only access static fields from static methods, which has
perfect sense - static methods don't know each and every class
instance to access their instance's fields.

AA2e72E je napisao/la:
I am getting the above error with this Class Library code:

namespace ClassLibrary1
{
public class Class1
{
private string FoundPathKey;
public string LastError
{
get { return FoundPathKey; }
}
public static string Read(string path, string key)
{
string keyval = "";
try
{
FoundPathKey = "";
keyval = Microsoft.Win32.Registry.GetValue(path, key,
"Missing").ToString();
if (keyval == "Missing")
{
throw new Exception("Either the path <" + path + "OR
the key <" + key + "does not exist");
}
}
catch (Exception MyExcep)
{
FoundPathKey = MyExcep.Message.ToString();
}
return keyval;
}
}
}

on the two lines where I assign a value to FoundPathKey and I do not have a
clue why.

Could somene please point out what it is that I am missing?

Thank you.
May 25 '07 #2

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

Similar topics

6
by: Andrew Mueller | last post by:
Hello all, I am working on a project, converting code from VB 6.0 to C#. I have a COM object (SDK.dll) referenced and am having some issues using it. I don't think it is specific to the object...
2
by: DC | last post by:
I have created the following abstract class: public abstract class BaseC { protected int _ID; protected string _name; protected abstract DataTable GetData(int ID); // intended to hit data...
1
by: TdJ | last post by:
No end of reading on the net and I can not get this to compile! The error message is: An object reference is required for the nonstatic field, method, or property...
7
by: Chris Clement | last post by:
I have been handed a project that someone else started and most of it was developed in the VS.NET design mode. For whatever reasons, when I try to make changes to the controls in VS.NET design...
5
by: Vicky via DotNetMonster.com | last post by:
Hi, I need help with "An object reference is required for the nonstatic field, method, or property 'dataReader.Class1.data'" Before I put folowing variable in class level, it works fine....
2
by: Beffmans | last post by:
Hi When I run this code: using System; namespace DelegateProject { public delegate void MyDelegate(string s);
6
by: tshad | last post by:
I am getting the following error for: C:\VSProjects\ClassLibrary4\NewHire.cs(72): An object reference is required for the nonstatic field, method, or property 'MyFunctions.NewHire.firstName' ...
2
by: simonZ | last post by:
I have class, which returns dataTable to populate my list box on some other pages: public class dataClass { private Int16 _lvlRights=1 public static DataTable dtAdv() {
2
by: rameshonweb | last post by:
Iam getting the error an object reference is required for the nonstatic field method or property 'System.Windows.Forms.Control.CreateGraphics()' for this part of code public static void...
4
by: cppquester | last post by:
I have a data set MMSDataAccess with: public partial class MMSDataSet : System.Data.DataSet { ... private TB_ACTHEATDATADataTable tableTB_ACTHEATDATA; ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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...

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.