Missing code after I reference dll in .NET project

I have .NET project that should reference dll(not a project reference) of class library.
The library has several classes and interfaces. I will explain only the ones that might be related to the problem.

Simple interface:

public interface IEmailMessageRepository : IGeneralRepository<EmailMessage>
{
    public Task<List<EmailMessage>> GetEmailsBySentStatus(bool sent);
}

Class that implements this interface:

public class EmailMessageRepository : GeneralRepository<EmailMessage>, IEmailMessageRepository
{
    public EmailMessageRepository(FishContext context) : base(context)
    {

    }
    public async Task<List<EmailMessage>> GetEmailsBySentStatus(bool sent)
    {
        return await _context.EmailMessages.Where(e => e.IsSent == sent).ToListAsync();
    }
}

and static class that extends IServiceCollection:

public static class ServiceCollectionsFish
{
    public static IServiceCollection RegisterFishServices(this IServiceCollection services, IConfiguration configuration)
    {
        services.AddDbContext<FishContext>(o =>
        {
            o.UseSqlServer(configuration.GetConnectionString("FishUA"));
            o.EnableDetailedErrors();
            o.EnableSensitiveDataLogging();
        });
        services.AddTransient<IEmailMessageRepository, EmailMessageRepository>();
        return services;
    }
}

Now, in another project that I want to reference this class library(dll), in the Program.cs I register my classes for DI:

        var host = Host.CreateDefaultBuilder()
            .ConfigureServices((context, services) =>
            {
                services.RegisterFishServices(config);
                services.AddTransient<IBasic, Basic>();
                services.AddTransient<IEmailMessageRepository, EmailMessageRepository>();
            }).Build();

Class that uses this repository:

private readonly IEmailMessageRepository _emailMessageRepository;

public Basic(IEmailMessageRepository emailMessageRepository)
{
    _emailMessageRepository = emailMessageRepository;
}

I can not build my project, because I get the following error:

“Error CS1061 ‘IEmailMessageRepository’ does not contain a definition for ‘GetEmailsBySentStatus’ and no accessible extension method ‘GetEmailsBySentStatus’ accepting a first argument of type ‘IEmailMessageRepository’ could be found (are you missing a using directive or an assembly reference?)”

When I open the ‘IEmailMessageRepository’, the body of the interface is empty.

Where may be the problem ?

  • 1

    I could be wrong but it sounds to me like your project is referencing a stale version of the defining assembly – perhaps in the Release folder where you meant Debug, or vice versa.

    – 

  • @500-InternalServerError In the build log of the class library I have this: 1->DataFish -> <path>\DataFish\bin\Release\net7.0\DataFish.dll 1>Done building project “DataFish.csproj”.

    – 




  • I wager you have by accident declared two or more IEmailMessageRepository interfaces in different namespaces in your first project, with one of those interfaces specifying GetEmailsBySentStatus, while the other remained empty. And in your other project, you are then using the accidental empty IEmailMessageRepository interface without having noticed it…

    – 




Leave a Comment