c# - 无法实现接口,因为任务没有匹配的返回类型方法
问题描述
我正在开发 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 方法的返回类型不正确,我不明白为什么,请帮忙!
解决方案
问题已解决,接口包含 Azure.Storage.Blobs 库,其中包含预定义的方法 BlobInfo,它的名称与我的模型 BlobInfo 冲突。因此,它只需要重命名该库的模型/排除。
推荐阅读
- google-cloud-platform - Google Cloud Storage 存储桶抛出错误“要计费的项目与已关闭的计费帐户相关联。”
- python - 如何在Python中的两个字符串之间拆分每个单独的值
- java - 如何在微服务的多个实例之间维护 SseEmitters 列表?
- laravel - Laravel:使用 Faker 播种嵌套的设置表
- java - 关闭插页式广告时,Facebook Audience Network 广告应用程序崩溃
- ldap - 启用邮件的安全组和分发邮件组的 LDAP 查询
- php - 检查请求的 url 以获取文本模式,然后执行某些操作
- java - 深拷贝 byte[] 是否使用 clone()?
- node.js - 如何在 mongodb 中查询嵌套非常深的对象?
- r - 为网络分析创建对