I have a set of C# files for a web application that I've inherited from a developer who's no longer around. I've created a solution in Visual Studio 2010 and added the existing files and subfolders to the solution from source control. One of the subfolders I created is called App_Code and mimics a subfolder that existed in our source control program. Inside this subfolder are a few C# classes. These classes are referenced in code behind files at the root (e.g., ActionPage.aspx.cs: ), but none of the code behind files can find the classes in App_Code. I get the usual error message, "The type or namespace 'ErrorLogger' [one of the classes] could not be found (are you missing a directive or an assembly reference?)" The App_Code subfolder doesn't look like a regular folder. I'm attaching a clip showing what it looks like:
.
I suspect it's a special Visual Studio folder name. Here's an example of the code in ActionPage that's calling ErrorLogger (and is giving the error message listed above):
ErrorLogger Err = new ErrorLogger();
And here's what the ErrorLogger class looks like:
using System;
using System.IO;
using System.Text;
public class ErrorLogger
{
public void Logger(string sPathName, string sErrMsg)
{
//- <--custom date time stamp & format for easy reading
string sLogFormat = DateTime.Now.ToShortDateString().ToString() + " " + DateTime.Now.ToLongTimeString().ToString() + " ==> ";
string sYear = DateTime.Now.Year.ToString();
string sMonth = DateTime.Now.Month.ToString();
string sDay = DateTime.Now.Day.ToString();
//string sErrorTime = sYear+sMonth+sDay;
string sErrorTime = sMonth + sDay + sYear;
//- <--Write error to a file
StreamWriter sw = new StreamWriter(sPathName + sErrorTime, true);
sw.WriteLine("------------------------------------------------------------------------------------------------");
sw.WriteLine(sLogFormat + sErrMsg);
sw.Flush();
sw.Close();
}
}
What am I missing?
Added 2/24/2015: I've found a somewhat unsatisfactory solution: I created a new VS 2010 solution and then chose File->Add->Existing Web Site. I now have the code in a website instead of a web application, but it does compile and run. Short of building the whole thing over again, I think this is the best I can do - unless anyone has any other suggestions.... And I do appreciate all the suggestions, folks, believe me. On a related topic, WHY does File->New->Project from Existing Code not give me the option for a Web Application? Redmond, if you're listening, add that!!
namespace
that will make your life a lot easier or look up how to use theusing
clause / statement in your class hearders if you are not familiar with how to find the namespace or default namespace then right click onAAT
in the project and select properties to see – MethodMan