473,396 Members | 1,814 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.

CA1822 Error

I've got the Warning :
Microsoft.Performance : The 'this' parameter of '....' is never used.Mark the member as static or use this in the method body or at least one prperty accessor, if appropriate.

to this code:

class CallFile
{
public String FindFile(string path)
{
try
{
XmlDocument ProjectFile = new XmlDocument();
ProjectFile.Load(path);

XmlNamespaceManager nsManager = new XmlNamespaceManager
(ProjectFile.NameTable);
nsManager.AddNamespace
("ns", "http://schemas.microsoft.com/developer/msbuild/2003");

String Wert = ProjectFile.SelectSingleNode
("/ns:Project/ns:PropertyGroup/ns:ProductVersion",nsManager).InnerText;
Console.Write(Wert + Environment.NewLine );
return Wert;
}//try
finally
{
Console.WriteLine("");
}//finally
}//Method
}



But when I try to solve the warning and make the method static I get following error:

Memeber '.......' cannot be accessed with an instance reference, qualify it with a type name instad

Can anyone please explain me, how I could solve error and warning?
Jun 8 '09 #1
5 9275
r035198x
13,262 8TB
Post the exact error message that you are getting. Most likely you are passing a parameter to a method but never using that parameter in that method.
Jun 8 '09 #2
Well, I thought I did.
I only leave out names given from me (file,namespace ...).

I'll will insert exact copy:
Warning 1
CA1822 : Microsoft.Performance : The 'this' parameter (or 'Me' in Visual Basic) of 'CallFile.FindFile(string)' is never used. Mark the member as static (or Shared in Visual Basic) or use 'this'/'Me' in the method body or at least one property accessor, if appropriate.

And when I make method static this error occures:
Error 1
Member 'MatchMaker.CallFile.FindFile(string)' cannot be accessed with an instance reference; qualify it with a type name instead
Jun 8 '09 #3
r035198x
13,262 8TB
Don't make it static if it doesn't need to be. The warning is because an instance method is not accessing any instance variables. The warning won't stop your code from compiling and running. The compiler is just telling you that instance methods usually access instance variables and if a method doesn't use instance variables then it can be called independently of any instance of the containing class meaning it can be made static.
Jun 8 '09 #4
Thank you!!
I think I came a littel bit closer.
It'd run without static, but I wanted to make "nice" code and solve all warnings occurring during static Code Analysis...but I think I will just ignore it :->
Jun 8 '09 #5
r035198x
13,262 8TB
If you do decide to make the method static then you use the class name to access it not an instance variable. If it doesn't access instance variables then it probably should be made static.
Jun 8 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
1
by: yanwan | last post by:
I met this problem in executing a c++ project in visual studio. Does anyone have suggestions to resolve "error lnk 2001"? --------------------Configuration: reconstruction - Win32...
5
by: Enos Meroka | last post by:
Hallo, I am a student doing my project in the university.. I have been trying to compile the program using HP -UX aCC compiler, however I keep on getting the following errors. ...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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.