方法,c#,asp.net,asp.net-mvc,asp.net-web-api,azure-storage"/>

首页 > 解决方案 > 无法实现接口,因为任务没有匹配的返回类型方法

问题描述

我正在开发 Microsoft Azure 存储服务的 .NETCore Web API 项目。

我有一个服务层 BlobService 正在实现 IBlobService 接口

public interface IBlobService
{
        public Task<BlobInfo> GetBlobAsync(string name);
       
}

其中 BlobInfo 是一个自定义类:

public class BlobInfo
    {
        public BlobInfo(Stream content, string contentType)
        {
            Content = content;
            ContentType = contentType;
        }

        public Stream Content { get; set; }
        public string ContentType { get; set; }
    }

BlobService 服务:

public class BlobService : IBlobService
    {
        public readonly BlobServiceClient _blobServiceClient;
        public BlobService(BlobServiceClient blobServiceClient)
        {
            _blobServiceClient = blobServiceClient;
        }

        public async Task<BlobInfo> GetBlobAsync(string name)
        {
            var containerClient = _blobServiceClient.GetBlobContainerClient("videos");
            var blobClient = containerClient.GetBlobClient(name);
            var blobDownloadInfo = await blobClient.DownloadAsync();
            return new BlobInfo(blobDownloadInfo.Value.Content, blobDownloadInfo.Value.ContentType);

        }

    }

在这一层出现一个错误,简而言之,Task <BlobInfo> GetBlobAsync 方法的返回类型不正确,我不明白为什么,请帮忙!

实现接口错误

标签: c#asp.netasp.net-mvcasp.net-web-apiazure-storage

解决方案


问题已解决,接口包含 Azure.Storage.Blobs 库,其中包含预定义的方法 BlobInfo,它的名称与我的模型 BlobInfo 冲突。因此,它只需要重命名该库的模型/排除。


推荐阅读