【问题标题】:Cannot implement interface because does not have matching returning type for Task<Custom class> method无法实现接口,因为 Task<Custom class> 方法没有匹配的返回类型
【发布时间】:2021-07-09 16:15:06
【问题描述】:

我正在开发 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 GetBlobAsync 方法的返回类型不正确,我不明白为什么,请帮忙!

【问题讨论】:

  • 请将错误添加为文本,而不是图像(如果可以的话)。
  • 从你的接口方法定义中移除public
  • @Fildor 我也写了我的查询,但以防万一有人想看到我添加图像的确切错误。
  • 无法复制:dotnetfiddle.net/yS0oUm
  • 或者您定义了多个BlobInfo?简而言之,可能是名称冲突,或者您可能需要尝试进行清理并重建。

标签: c# asp.net asp.net-mvc asp.net-web-api azure-storage


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多