locked
Cannot access a non-static member RRS feed

  • Question

  • I try use properties Context.Cache. But it finish with this errror:
    Error1 Cannot access a non-static member of outer type 'SecureWebService.Service1' via nested type 'SecureWebService.Service1.Reader
    Any advice , How can I use properties Context.Cahe??? Variable string path must be static.

        public class Service1 : System.Web.Services.WebService
        {
    
            public static string path = "C:\\";
    
            public class Reader
            {
                private void ini()
                {
                    loadFromCahe();
                }
            }
    
            [WebMethod]
            public void set(string _path)
            {
                Context.Cache.Insert("path", _path, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
    
            public void loadFromCahe()
            {
                Service1.path = (string)Context.Cache["path"];
            }
        }
    Monday, September 14, 2009 2:50 PM

Answers

All replies

  • What is the "public class Reader" supposed to be?  That seems to be the issue to me.  The code you have right now doesn't compile at all.  You should have multiple errors here.  Perhaps you could remove the entire block "public class Reader".  I don't really see a purpose behind it. 


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser
    • Proposed as answer by liurong luo Wednesday, September 16, 2009 1:08 PM
    • Marked as answer by liurong luo Friday, September 18, 2009 2:48 AM
    Monday, September 14, 2009 2:55 PM
  • What is the "public class Reader" supposed to be?  That seems to be the issue to me.  The code you have right now doesn't compile at all.  You should have multiple errors here.  Perhaps you could remove the entire block "public class Reader".  I don't really see a purpose behind it. 


    Coding Light - Illuminated Ideas and Algorithms in Software
    Coding Light WikiLinkedInForumsBrowser

    Sory, All code :

    public class Service1 : System.Web.Services.WebService
        {
    
            public static string path = "C:\\";
    
            public class Reader
            {
                private void ini()
                {
                    loadFromCahe();
                }
            }
    
            [WebMethod]
            public void set(string _path)
            {
                Context.Cache.Insert("path", _path, null, DateTime.Now.AddMinutes(10), TimeSpan.Zero);
            }
    
            public void loadFromCahe()
            {
                Service1.path = (string)Context.Cache["path"];
            }
    }
    Monday, September 14, 2009 3:09 PM
  • Maybe I'm just overlooking something here, but whats the difference between that and your original post?
    おろ?
    Monday, September 14, 2009 6:19 PM