Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

242
Views
Why does this error state my class does not implement this interface method?

I have a class that implements an interface and legacy from other class.

I don't know why my code is bad.

The error I get is:

CS0738 'SizeTypeService' does not implement interface member 'IGenericService<ItemType>.GetAll()'.

'GenericService<SizeType>.GetAll()' cannot implement 'IGenericService<ItemType>.GetAll()' because it does not have the matching return type of 'Task<List<ItemType>>'.

I think that my interface and class are ok. I don't know why VS is throwing an error.

public interface IGenericService<TEntity> where TEntity : class
{
    Task<List<TEntity>> GetAll();
    Task<TEntity> GetById(int id);
    Task<TEntity> Insert(TEntity entity);
    Task<TEntity> Update(TEntity entity);
    Task Delete(int id);
}

public class GenericService<TEntity> : IGenericService<TEntity> where TEntity : class
{
    private IGenericRepository<TEntity> genericRepository;

    public GenericService(IGenericRepository<TEntity> genericRepository)
    {
        this.genericRepository = genericRepository;
    }

    public async Task Delete(int id)
    {
        await genericRepository.Delete(id);
    }

    public async Task<List<TEntity>> GetAll()
    {
        return await genericRepository.GetAll();
    }

    public async Task<TEntity> GetById(int id)
    {
        return await genericRepository.GetById(id);
    }

    public async Task<TEntity> Insert(TEntity entity)
    {
        return await genericRepository.Insert(entity);
    }

    public async Task<TEntity> Update(TEntity entity)
    {
        return await genericRepository.Update(entity);
    }
}

public interface ISizeTypeService : IGenericService<ItemType>
{
    Task<List<SizeType>> GetAllSizeTypeActives(int id);
    Task LogicDelete(int id);
}

public class SizeTypeService : GenericService<SizeType>, ISizeTypeService
{
    private ISizeTypeRepository sizeTypeRepository;

    public SizeTypeService(ISizeTypeRepository sizeTypeRepository) : base(sizeTypeRepository)
    {
        this.sizeTypeRepository = sizeTypeRepository;
    }

    public Task<List<SizeType>> GetAllSizeTypeActives(int id)
    {
        return sizeTypeRepository.GetAllSizeTypeActives(id);
    }

    public Task LogicDelete(int id)
    {
        return sizeTypeRepository.LogicDelete(id);
    }
}
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You have defined your ServiceTypeClass as

public class SizeTypeService : GenericService<SizeType>, ISizeTypeService
{
   ...
}

So you are telling the compiler that ServiceTypeService uses the base class GenericService with TEntity defined as SizeType. BUT, the ISizeTypeService interface it also derives from is telling the compiler that this class also implements the IGenericService interface where TEntity is a ItemType class. But nowhere in the code is class that implements the method GenericService<ItemType>.GetAll().

So, the error is saying "hey - I found the method matching GenericService<SizeType>.GetAll() - where TEntity is SizeType, but I cannot find one that matches IGenericService<ItemType>.GetAll()"

To fix you need to change the ISizeTypeService definition to use the same class as GenericService for TEntity

e.g.

public interface ISizeTypeService : IGenericService<SizeType>
{
   ...
}

NOTE: The generic parameter is now SizeType which matches the GenericService<SizeType> base class that SizeTypeService derives from.

over 4 years ago · Santiago Trujillo Report

0

Simply Ged explained clearly. As code in your ISizeTypeService

public interface ISizeTypeService: IGenericService<ItemType>
    {
    }

Because you get Task<List> IGenericRepository.GetAll() in GenericService. So

enter image description here

I also got a similar error, then I added the following code in SizeTypeService.cs and the error went away

Task<List<ItemType>> IGenericService<ItemType>.GetAll()
        {
            throw new NotImplementedException();
        }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!