Unable to "require" or "use" classes and functions from a included .cs file

I am using Visual web developer 2005 Express Edition and i have right clicked the project file in SolutionExplorer and included a .csharp file.It got added inside a App_Code directory.

When i created an object for the class constants the dropdown was visible and constants class was selected.

Constants cons = new Constants();

When i ran the webform an error occured indicating:

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

Willfin David.



Answer this question

Unable to "require" or "use" classes and functions from a included .cs file

  • srinivasintouch

    You need to have a line like:

    using Constants;

    in your code at the top (before) the classes that use the code defined in the Constants namespace. Look for other "using" statements.

    This is the blank windows app project created by C# express. The using statements say that the code therein can access the various functions referenced.

    using System;

    using System.Collections.Generic;

    using System.Windows.Forms;

    namespace WindowsApplication1

    {

    static class Program

    {

    /// <summary>

    /// The main entry point for the application.

    /// </summary>

    [STAThread]

    static void Main()

    {

    Application.EnableVisualStyles();

    Application.SetCompatibleTextRenderingDefault(false);

    Application.Run(new Form1());

    }

    }

    }



  • SamUNVA

    This question was reposted and answered correctly in this thread:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=267405&SiteID=1


  • Jon Rauschenberger

    I had the same problem but it was resolved just by re-building the entire project.

    Cheers!

  • Hank2

    I have used all the namespace as above.

    using System;

    using System.Collections.Generic;

    using Constants;

    But the same error occurs and since i have included "using Constants" it is now showing the error :

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

    Willfin David.


  • Caroline Wise

    hi,

    i'm not expert with asp.net but what i know if you add assembly to your site you need to regester it first to be able to use it, i saw that when i tried to use asp.net in dreamweaver it insisted to add the assembly to the page i don't know how it works or what is that because i simply scaped it and wrote my code

    but first b4 you look for how to register assembly on the server be sure all your classes wrapped by the same namespaces

    hope that helps



  • Unable to "require" or "use" classes and functions from a included .cs file