C# – Compiler Error CS1061

.net-3.5asp.netccompiler-construction

I have the following class…

public class MyCustomLogger
{

public static int DEFAULT_INFO = 0;
public static int DEFAULT_LOGIN = 1;

//etc

public static void Log( ... )
{
 doStuff(...);
}
public static void Log( ... , ... )
{
 doStuff(...);
}
private static void doStuff(...)
{
//doLots of Stuff
}

So when I call MyCustomLogger.Log(...); from another Custom Class… it works fine. No compile errors…nothing. It just works

When I call it from SuchAndSuch.master code behind… it works fine. No Compile errors…nothing. It just works.

When I call it from SuchAndSuch.ascx code behind… it works fine. No Compile errors…nothing. It just works.

However… when I call it from SuchAndSuch.aspx code behind… it doesn't work. I'm getting 'MyCustomLogger' does not contain a definition for 'Log'

I'm getting this from any aspx page I add it to.

EDIT
Here's a snippet from the aspx pages i'm trying to add it to

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Logout : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //doStuff
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        MyCustomLogger.Log(MyCustomLogger.DEFAULT_INFO);

Has anyone else experienced this?

Best Answer

Here are a few ideas on what might be causing this:

  1. If this is a web site project, which I'm guessing because your extract does not include a namespace, do you have another class in your app_code folder with the MyCustomLogger name?
  2. If this page is in the Master Page, is the Master Page exposing something named MyCustomLogger as a public property and conflicting with the app_code definition?
  3. If this is a web application project, the problem could be because the Namespace declaration is missing on the page.
Related Topic