You need to enable JavaScript to run this app. 实现IBlobService接口时提示GetBlobAsync方法的Task<BlobInfo>返回类型不匹配错误
优惠活动
大模型
产品
解决方案
定价
更多

实现IBlobService接口时提示GetBlobAsync方法的Task<BlobInfo>返回类型不匹配错误

项目背景
  • 正在开发一款基于Microsoft Azure存储服务的.NET Core Web API项目
  • 已编写实现IBlobService接口的服务层BlobService类,当前编译时遇到接口实现匹配报错,提示GetBlobAsync方法的返回类型不匹配,开发者无法理解报错原因,寻求帮助。

接口与自定义类型定义

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);
    }
}

报错信息

编译器明确提示GetBlobAsync方法的Task返回类型不正确,附报错截图:
接口实现报错截图


内容的提问来源于stack exchange,提问作者Kartik Rai 5-Yr IDD Comp Sci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.25 23:36:04