Home > Enterprise >  Compiler Error after upgrading from .Net Core 2 to .Net 6
Compiler Error after upgrading from .Net Core 2 to .Net 6

Time:06-03

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!

CodePudding user response:

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.

  • Related