0

I upgraded from .Net Core 2 to .Net 6. One of the errors that it caused was this:

Error CS1106 Extension method must be defined in a non-generic static class

It is happening on the public class BookController line.

So I did some research on the Microsoft site and I removed the static keyword from the LateFee method.

But that doesn't fix the error.

Is there anything else I need to do?

Here is my class:

public class BookController
    : LibraryController<BookClub, Books>
{

    public BookController(BookConfig<BookClub> ctx) 
        : base(ctx)
    {
    }

    private static bool LateFee(BookClub original, Books b)
    {
        return original.Date?.Id != b.CheckoutDate.TrimToNull();
    }
}

Here is the parent class:

public class LibraryController()

    [HttpPost("byLocation/{id}")]
    public IActionResult PostBookRequest(this Int32 id)
    {
        using (var tran = Session.BeginTransaction()) {
            foreach (var book in LibraryService.CreateHold(id)) {
                Session.Save(book);
            }
            tran.Commit();
            return NoContent();
        }
    }

Thanks!

11
  • 2
    Extension methods contain the this keyword as part of the first parameter in an extension method's parameter list. Are you sure you haven't declared such a method in this class? Commented Jun 2, 2022 at 14:23
  • 4
    @Fildor the parent class has that this keyword. Could that be it? Commented Jun 2, 2022 at 14:38
  • 1
    Post the code for the parent class. Commented Jun 2, 2022 at 14:39
  • 1
    I find it very hard to believe that going from .NET Core 2 to .NET 6 would give you a compile error like this. That parent class you have posted would never have compiled in any version of C#/.NET. You need to provide a minimal reproducible example otherwise this question will be closed. Commented Jun 2, 2022 at 14:52
  • 2
    Even the line public class LibraryController() has never been valid C# code, that has NEVER compiled. Commented Jun 2, 2022 at 14:59

1 Answer 1

2
public IActionResult PostBookRequest(this Int32 id)

Remove the this from that line, it's a syntactic error in .Net Core 2 and it remains a syntax error in .Net6.

Sign up to request clarification or add additional context in comments.

2 Comments

thank you, so you mean so it looks like this? public IActionResult PostBookRequest(Int32 id) ?
Or even better, public IActionResult PostBookRequest(int id)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.