4

Im new to c# and im creating a new web app. As usual i create a library of public functions used by the application in general.

Im using VS.net 2008, I created a project new projectwith the followin structure: root --App_Code globalClass.cs --scripts Default.aspx Default.aspx.cs

I need to import/using the globalClass inside App_Code/globalClass.cs Inside the code Behind of Default.aspx or any other.

This is the content of App_Code/globalClass.cs

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;


namespace sgmedcs.globalClass
{
    public class claseGlobalX : System.Web.UI.Page
    {
        //HttpContext httpActual = HttpContext.Current;

        public string cargarSQL(string queryStr, string queryType)
        {
          //Scripting
        }
    }
}

I also used as namespace sgmed.App_Code.globalClass and sgmedcs.AppCode.globalClass

On the Default.aspx.cs i added using sgmedcs.globalClass; Or using sgmed.App_Code.globalClass; Or using sgmedcs.AppCode.globalClass

All of these approaches gives me "The type or namespace name 'claseGlobal' does not exist in the namespace 'sgmedcs' (are you missing an assembly reference?)"

What im missing, thanks for the help.

1
  • I think if you change the namespace to namespace sgmedcs it should resolve your issue. Commented Oct 3, 2013 at 17:09

2 Answers 2

15

Go into the properties of the class, and change the Build Action to Compile.

Sign up to request clarification or add additional context in comments.

1 Comment

I Keep the namespace sgmedsc.globalClass. And in the default.aspx i added sgmedsc.globalClass; In the properties i changed the Build Action to Compile, as James Johnson said. Thanks
0

Also worth mentioning: if your project is a "web site" rather than a "web application", there is no build action option in the properties. However, the same error can arise for various reasons. One would be that the App_Code class is given a namespace, and the other file isn't referring to it with a fully qualified name including the namespace. Another would be that the page where you're trying to use the class is inside a subdirectory that, on IIS, is marked as an Application, which gives it an entirely separate context where the classes in a parent directory's App_Code directory aren't accessible. In that case you'd need either to remove the sub-Application, or, if you need it, give it its own App_Code directory with necessary classes.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.