C# 没有从';类型1';至';类型2';

C# 没有从';类型1';至';类型2';,c#,asp.net,visual-studio-2017,C#,Asp.net,Visual Studio 2017,我试图做一个网络项目,但面临一个问题 代码: 公共启动(IConfiguration配置) { 配置=配置; } 公共IConfiguration配置{get;} //此方法由运行时调用。使用此方法向容器中添加服务。 public void配置服务(IServiceCollection服务) { services.AddMvc(); services.AddSingleton(配置); services.addScope(); services.AddDbContext(options=>opt

我试图做一个网络项目,但面临一个问题

代码:

公共启动(IConfiguration配置)
{
配置=配置;
}
公共IConfiguration配置{get;}
//此方法由运行时调用。使用此方法向容器中添加服务。
public void配置服务(IServiceCollection服务)
{
services.AddMvc();
services.AddSingleton(配置);
services.addScope();
services.AddDbContext(options=>options.UseSqlServer(Configuration.GetConnectionString(“LibraryConnection”));
}
但我有一个错误:

错误CS0311类型“Library.LibraryAssetService”不能用作泛型类型或方法“ServiceCollectionServiceExtensions.AddScoped(IServiceCollection)”中的类型参数“TImplementation”。没有从“Library.LibraryAssetService”到“LibraryData.ILibraryAssetService”的隐式引用转换。库C:\Users\Austina\source\repos\Library\Library\Startup.cs 29处于活动状态

我用谷歌搜索了所有地方,但没有任何帮助。也许我遗漏了一些明显的东西

还使用类进行编码:

public class LibraryAssetService : ILibraryAssetService
{
    private LibraryContext _context;
    private int videoId;

    public LibraryAssetService(LibraryContext context)
    {
        _context = context;
    }

    public LibraryAssetService()
    {
    }

    public void Add(LibraryAsset newAsset)
    {
        _context.Add(newAsset);
        _context.SaveChanges();
    }

    public LibraryAsset Get(int id)
    {
        return _context.LibraryAssets
            .Include(a => a.Status)
            .Include(a => a.Location)
            .FirstOrDefault(a => a.Id == id);
    }

    public IEnumerable<LibraryAsset> All => _context.LibraryAssets
            .Include(a => a.Status)
            .Include(a => a.Location);

    public int Id => throw new NotImplementedException();

    public string ImageUrl => throw new NotImplementedException();

    public string Title => throw new NotImplementedException();

    public string GetAuthorOrDirector(int id)
    {
        var isBook = _context.LibraryAssets
            .OfType<Book>().Any(a => a.Id == id);

        var isVideo = _context.LibraryAssets
            .OfType<Video>().Any(video => videoId == id);

        return isBook
            ? GetAuthor(id)
            : GetDirector(id);
    }

    public LibraryAsset GetById(int id)
    {
        return _context.LibraryAssets
            .Include(asset => asset.Status)
            .Include(asset => asset.Location)
            .FirstOrDefault(asset => asset.Id == id);
    }

    public LibraryBranch GetCurrentLocation(int id)
    {
        return _context.LibraryAssets.FirstOrDefault(a => a.Id == id).Location;
    }

    public string GetDeweyIndex(int id)
    {
        if (_context.Books.Any(book => book.Id == id))
        {
            return _context.Books.FirstOrDefault(book => book.Id == id).DeweyIndex;
        }
        else
        {
            return "";
        }
    }

    public string GetIsbn(int id)
    {
        if (_context.Books.Any(a => a.Id == id))
             {
            return _context.Books
                .FirstOrDefault(a => a.Id == id).ISBN;
        }
        else
        {
            return "";
        }
    }
    public LibraryCard GetLibraryCardByAssetId(int id)
    {
        return _context.LibraryCards
            .FirstOrDefault(c => c.Checkouts
                .Select(a => a.LibraryAsset)
                .Select(v => v.Id).Contains(id));
    }

    public string GetTitle(int id)
    {
        return _context.LibraryAssets.First(a => a.Id == id).Title;
    }

    public string GetType(int id)
    {
        var book = _context.LibraryAssets.OfType<Book>()
             .Where(b => b.Id == id);
        return book.Any() ? "Book" : "Video";
    }
    private string GetAuthor(int id)
    {
        var book = (Book)Get(id);
        return book.Author;
    }
    private string GetDirector(int id)
    {
        var video = (Video)Get(id);
        return video.Director;
    }

    public IEnumerable<ILibraryAssetService> GetAll()
    {
        throw new NotImplementedException();
    }

    internal class LibraryContext_context
    {
    }
}
公共类LibraryAssetService:ILibraryAssetService
{
私人图书馆环境(u context);;
私有int videoId;
公共图书馆资产服务(图书馆上下文)
{
_上下文=上下文;
}
公共图书馆资产服务()
{
}
公共作废添加(LibraryAsset新资产)
{
_添加(新资产);
_SaveChanges();
}
公共图书馆资产获取(int id)
{
return\u context.LibraryAssets
.包括(a=>a.Status)
.包括(a=>a.位置)
.FirstOrDefault(a=>a.Id==Id);
}
public IEnumerable All=>\u context.LibraryAssets
.包括(a=>a.Status)
.包括(a=>a.位置);
public int Id=>抛出新的NotImplementedException();
公共字符串ImageUrl=>抛出新的NotImplementedException();
公共字符串Title=>抛出新的NotImplementedException();
公共字符串getAuthorOrDirectory(int id)
{
var isBook=\u context.LibraryAssets
.OfType().Any(a=>a.Id==Id);
var isVideo=\u context.LibraryAssets
.OfType().Any(video=>videoId==id);
还书
?获取作者(id)
:GetDirector(id);
}
公共图书馆资产GetById(int id)
{
return\u context.LibraryAssets
.Include(资产=>asset.Status)
.Include(资产=>asset.Location)
.FirstOrDefault(asset=>asset.Id==Id);
}
公共图书馆分支GetCurrentLocation(内部id)
{
返回_context.LibraryAssets.FirstOrDefault(a=>a.Id==Id).Location;
}
公共字符串GetDeweyIndex(int id)
{
if(_context.Books.Any(book=>book.Id==Id))
{
返回_context.Books.FirstOrDefault(book=>book.Id==Id).DeweyIndex;
}
其他的
{
返回“”;
}
}
公共字符串GetIsbn(整数id)
{
if(_context.Books.Any(a=>a.Id==Id))
{
return\u context.Books
.FirstOrDefault(a=>a.Id==Id).ISBN;
}
其他的
{
返回“”;
}
}
公共图书馆卡GetLibraryCardByAssetId(内部id)
{
返回_context.LibraryCards
.FirstOrDefault(c=>c.签出
.选择(a=>a.LibraryAsset)
.Select(v=>v.Id).Contains(Id));
}
公共字符串GetTitle(int-id)
{
返回_context.LibraryAssets.First(a=>a.Id==Id).Title;
}
公共字符串GetType(int-id)
{
var book=\u context.LibraryAssets.OfType()的
。式中(b=>b.Id==Id);
返回book.Any()?“book”:“Video”;
}
私有字符串GetAuthor(int id)
{
var book=(book)Get(id);
归还书。作者;
}
私有字符串GetDirector(int-id)
{
var video=(video)Get(id);
返回视频。导演;
}
公共IEnumerable GetAll()
{
抛出新的NotImplementedException();
}
内部类LibraryContext\u context
{
}
}

这应该是由名称空间冲突引起的,您有两个同名的类或接口,它们位于不同的名称空间中

尽量使用like

services.addScope();

您需要更正上述完全限定的命名空间,因为编译错误表明,
Library.LibraryAssetService
未实现
LibraryData.ILibraryAssetService

您没有实现接口。通过类实现接口,如下所示:

public class LibraryAssetService: ILibraryAssetService
{
///....
}

是否确定在另一个项目类库中没有另一个
LibraryAssetService
?仍然显示相同的错误消息?你现在用什么型号的
services.AddScoped
仍然相同,services.AddScoped();
LibraryData.LibraryAssetService是否实现了LibraryData.ILibraryAsset?当我尝试您的建议时,同样的错误也会发生,但VS提供了简化名称的功能,并且在最后一行它仍然获得了服务。addScope(),我为此尝试了几种组合,但我认为我不完全理解这一部分。。。
services.AddScoped<LibraryData.ILibraryAssetService, Library.LibraryAssetService>(); 
public class LibraryAssetService: ILibraryAssetService
{
///....
}