views:

426

answers:

2

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?

+1  A: 

Hey,

Is there another type in the page that's MyCustomLogger that there is a conflict (can't resolve the correct type? Can you post any code to help us see the issue?

Brian
+4  A: 

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.
Jeff Siver
That answers it. I'm still new to C# and don't fully understand, among many other things, the NEED to declare a namespace for this class.But... Adding a namespace to MyCustomLogger.cs fixed the problem. I have no idea why~Thanks!
Robert
Namespaces are critical to understand when coding any DotNet language. You can find a decent explanation of them from MS at http://msdn.microsoft.com/en-us/library/dfb3cx8s.aspx.
Jeff Siver