1
namespace PROJ.Service {
   public static class ExceptionDatesUpdateService {
        public static ExceptionDatesUpdateService()
        {
        }

        public static bool IsServiceRunning() {
            return _updateThread != null && _updateThread.IsAlive;
        }
   }
}

当我尝试使用上面的静态类时,它说它不可访问。为什么?参考存在。

using PROJ.Service;
namespace PROJ.admin {
  public void ProcessRequest(HttpContext context) {
    bool ch = ExceptionDatesUpdateService.IsServiceRunning();
  }
}

感谢大家。问题被发现了。当我解决其他错误并编译它时。它消失了。我是 C# 新手,很抱歉这个愚蠢的问题。:)

4

4 回答 4

1

Assuming you've added the appropriate project reference, one problem I see is that static type initializers cannot have access modifiers. Try this:

public static class ExceptionDatesUpdateService {
    static ExceptionDatesUpdateService()
    {
    }
}

Of course, if there's nothing inside the initializer, you can just remove it entirely.

于 2013-11-08T04:22:49.427 回答
0

Check if Target Framework is same in the project properties for both the projects.

于 2013-11-08T04:28:44.013 回答
0

This is often caused by different .NET framework versions being set in the project properties. For instance, one project may be .NET 3.5 and you're trying to reference a .NET 4.0 project.

It can also be caused by a similar x64 vs x86 mismatch.

Usually the reference itself will have a warning icon next to it.

于 2013-11-08T04:22:51.813 回答
0
namespace PROJ.admin 
{
    public static class NewClass
    {
        public void ProcessRequest(HttpContext context)
        {
            bool ch = ExceptionDatesUpdateService.IsServiceRunning();
        }
    }
}

试试这个工作

于 2013-11-08T04:58:22.087 回答