locked
Class not found when web application is publish. CS0234: The type or namespace name 'newclassy' does not exist in the namespace 'test_5_class' (are you missing an assembly reference?) RRS feed

  • Question

  • User799222684 posted

    I'm new to c#.  this code WORKS running in Visual Studio. When I publish it to a web site, I get this error.

    ------- newclassy.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace test_5_class
    {
        public class newclassy
        {
            public string class_time { get; set; }
    
            public string DoSomething()
            {
                DateTime localDate = DateTime.Now;
                return string.Format("newclassy: {0}", localDate.ToString());
    
            }
    
        }
    }

    ----   Webform1.aspx

    <%@ Page Language="C#" AutoEventWireup="true" Codefile="WebForm1.aspx.cs" Inherits="test_5_class.WebForm1" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
    
            <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
            <asp:Label ID="Label2" runat="server" Text="Labe2"></asp:Label>
        </div>
        </form>
    </body>
    </html>
    

    --------   Webform1.cs

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using test_5_class;
    
    namespace test_5_class
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                DateTime localDate = DateTime.Now;
                Label1.Text= string.Format("Local date and time: {0}", localDate.ToString() );
    
                var x = new  test_5_class.newclassy();// <ERROR is on this line . I have tried various ways.
                Label2.Text = x.DoSomething();
            }
        }
    }

    I'm using Visual Studio 2015. I added this newclassy.cs to my project.

    Any suggestions?


    TIA

    Steve42

    Friday, November 30, 2018 7:34 PM

All replies