Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

243
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda