Search code examples
c#referenceapp-code

C# asp.net - The type or namespace name 'Helper' could not be found (are you missing a using directive or an assembly reference?)


I'm reworking someone else's code, where they had a helper class with way to much code that shouldn't be there (data access, business logic, everything had slowly been shoved in there).

I've moved the relevant code into the appropriate pre-existing classes and created a separate, brand new helper class in the appropriate project, but all my references to this class simply don't work.

Here's a simple view of how my class looks (names slightly changed);

namespace Company.Web.Application.Reporting 

{
    public class ReportHelper
    {
    here I have a bunch of methods
    }
}

and here is how it is being referenced;

using Company.Web.Application.Reporting;

namespace Company.Web.Application.App.Reports
{
    public partial class PlansReports : PageBase
    {
        //This is the problem part
        private ReportHelper Helper = new ReportHelper(); 
        heaps of other code with no problems here...
    }
}

My problem is that the I get the following error, everywhere that I try to access my new helper.

The type or namespace name 'ReportHelper' could not be found (are you missing a using directive or an assembly reference?)

All my using statements are there, I have the appropriate references in each relevant project, yet this still persists. At this point I am totally stuck, I just need to get this referencing issue sorted out so I can ensure all my helper methods work correctly.

Any help is greatly appreciated,

Pat.


Solution

  • OK, I found the problem (actually a colleague did)

    This original Helper class was contained in the app_code folder of my main project, which as I have just learned, handles compiling differently to all other folders in a project. Code in here is compiled at run time, rather than during the build. When I created my new classes, they were in the app_code folder because I used code rush to extract the class to a new file, which kept it in the same location...after which I moved them to their "sensible" location. Unfortunately they still had the build action of "Content" inherited from their previous presence in the app_code folder. So, on the new class file, I simply changed its build action to "Compile" and now all is well with the world.

    Cheers,

    Pat.