【问题标题】:Unable to upload file after moving from .netcore 2.2 to 3.1从 .net core 2.2 移动到 3.1 后无法上传文件
【发布时间】:2020-06-12 04:46:07
【问题描述】:

我有一个为上传文件而构建的服务。 有 2 个程序集:一个带有 ApiController,另一个带有逻辑。

控制器:

public async Task<UploadFileResponse> UploadFromUrl([Required] string url, [FromQuery] string policy = null)
{
    return await _fileStorageService.UploadFromUrlAsync(url, policy);
} 

还有业务:

public abstract class BaseFileStorageService<TOptions> : IFileStorageService
{
...
    public async Task<UploadFileResponse> UploadFromUrlAsync(string url, string policyName = null, CancellationToken cancellationToken = default) {
        var fileName = Path.GetFileName(uri.LocalPath);

        ... //http request for the file

        var fileDataStream = await downloadResponse.Content.ReadAsStreamAsync();
        if (contentLength == null)
            throw new Exception("File upload error");

        var formFile = new FormFile(fileDataStream, 0, contentLength.Value, null, fileName)
        {
            Headers = new HeaderDictionary(),
            ContentType = contentType
        };
    }
}

我添加了以下软件包:

Microsoft.AspNetCore.Http v.2.2.2 和 Microsoft.AspNetCore.Http.Features 2.2.0(我试过 3.1.2 但行为是一样的)

这两个项目都是使用 .net core 3.1 构建的。当前安装的版本是 3.1.102。

A 可以与控制器处的调试器中断,但是当我尝试进入业务逻辑时,我收到以下消息:

System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Http.Internal.FormFile' from assembly 'Microsoft.AspNetCore.Http, Version=3.1.2.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'

我花了一天时间来解决这个问题。并且不知道如何使它工作。

可能是什么原因以及如何解决?

【问题讨论】:

    标签: c# asp.net-core .net-core .net-core-3.1


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2021-08-31
    • 2020-10-05
    • 2020-08-22
    • 1970-01-01
    • 2020-05-28
    • 2020-05-27
    • 1970-01-01
    • 2021-09-02
    相关资源
    最近更新 更多