Page 2 of 2 FirstFirst 12
Results 41 to 42 of 42

Thread: Where to put general procedures in C#

  1. #41

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2010
    Posts
    805

    Re: Where to put general procedures in C#

    Quote Originally Posted by PlausiblyDamp View Post
    Look at what the error message is saying. It is stating that an object reference is required for a non-static method - there is absolutely nothing there that indicates this is a problem with nuget. Have you tried googling that error? Have you tried seeing if there is any difference between that method and the one that works (especially any differences that might make sense in relation to the error message)?

    You don't compile a Shared Project, it is compiled into the project that uses it, that is why you cannot add nuget packages to the shared project - they are added to the project that is using your shared code.

    The error messages exist for a reason, just because you are using a shared project doesn't mean any and all errors are automatically due to the existence of the shared project.
    Thanks a lot for your help.
    I googled that error and after reading about it, I guess I have found out how to fix it.
    I just changed
    Code:
            public int RunSqlReturnInt_Shared(SQLiteConnection conn, string sql, int AltValForNull = 0, int AltValForNoRec = 0)
            {
                  ......
            }
    To:
    Code:
            public static int RunSqlReturnInt_Shared(SQLiteConnection conn, string sql, int AltValForNull = 0, int AltValForNoRec = 0)
            {
                  ......
            }
    And now everything works fine.

    Just I need to make sure that I have done the right fix, because it is always possible that the problem may have gone away as a result of a change (a "bad fix") that is not the best way to fix the problem, and that as a result of the "bad fix", I may later experience some other unexpected problems.

    Have I fixed the problem the right way (by adding the word "static" before the name of the method)?
    Or, should I have fixed it in a different way?

    Please advise.
    Thanks.

  2. #42
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,711

    Re: Where to put general procedures in C#

    Why would you think this is possibly a bad fix? The error message told you that the method needed to be a static method, you made it a static method and the error went away.

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width