Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

244
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda