【发布时间】:2020-03-13 05:06:41
【问题描述】:
使用 IFormFile 时,我在运行时收到此错误:
无法从程序集“Microsoft.AspNetCore.Http, Version=3.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60”加载类型“Microsoft.AspNetCore.Http.Internal.FormFile”。
我已经尝试添加包:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Http" Version="2.2.2" />
<PackageReference Include="Microsoft.AspNetCore.Http.Features" Version="3.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Core" Version="2.2.5" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Http" Version="3.0.0" />
<PackageReference Include="Microsoft.Net.Http.Headers" Version="2.2.0" />
using Microsoft.AspNetCore.Http.Internal;
IFormFile f = new FormFile(memoryStream, 0, memoryStream.Length, "test", "test.pdf");
FormFile Aspnetcore 3.0 的文档存在。但是,当检查我的 sdk 时,而不是使用 3.0.它仅在 .net core 2.2 中可用。我安装了 2.2 和 3.0 版本
区域组装 Microsoft.AspNetCore.Http,版本=2.2.0.0,文化=中性,PublicKeyToken=adb9793829ddae60
// C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.http\2.2.0\lib\netstandard2.0\Microsoft.AspNetCore.Http.dll
#endregion
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
namespace Microsoft.AspNetCore.Http.Internal
{
public class FormFile : IFormFile
}
【问题讨论】:
-
您是否尝试将您的引用更新为全部为
3.0.0?http2.2.2和http.features3.0.0可能是问题所在 -
感谢您的评论,我找不到Microsoft.AspNetCore.Http 3.0.0版,nuget.org/packages/Microsoft.AspNetCore.Http
-
这可能是 X-Y 问题。只是好奇:为什么要通过
new FormFile手动创建IFormFile实例? -
我正在调用一个返回文件的 api,我必须再次将其发送到另一个接收 IFormFile 的 api
-
@Exec21 如果是这种情况,则无需调用
FormFile。刚刚通过HttpClient发送了一个文件。
标签: c# asp.net-core