C# – Why can I access static class method in App_Code for an ASP.NET project NOT for an MVC2 Project

asp.netasp.net-mvcc

In the same asp.net MVC2 project (no problem when it is a pure ASP.NET project), I have created 2 classes in App_Code without no namespace, one is normal class, the other is static.

I can access public methods of instance class from anywhere, I cannot access public methods of the static class. Why ? And how can I access them then ?

    public class MyWebservice
    {

        public stMyWebservice()
        {                                       

        }

        public String getText() {
        }
    }


    public static class Helper
    {

        public static String getText()
        {




        }
    }

I access the static class inside the index.aspx like this:

<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>
<script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
        Helper.getText();                  
    }
</script>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Home Page
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2><%: ViewData["Message"] %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
    </p>
</asp:Content>

Best Answer

Be sure that the Build Action for the class is set to Compile.

Go to your App_Code folder, and select your class. Look in the properties page. Find Build Action. Set it to Compile. Then you should have access to the methods and properties of that object elsewhere in your application.