I have a service that is built for uploading files. There are 2 assemblies: the one with ApiController and the other with the logics.
Controller:
public async Task<UploadFileResponse> UploadFromUrl([Required] string url, [FromQuery] string policy = null)
{
return await _fileStorageService.UploadFromUrlAsync(url, policy);
}
And the business:
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
};
}
}
I have added the following packages:
Microsoft.AspNetCore.Http v.2.2.2 and Microsoft.AspNetCore.Http.Features 2.2.0 (I've tried 3.1.2 but the behaviour is the same)
Both projects are built with .net core 3.1. The currently installed version is 3.1.102.
A can break with the debugger at the controller but when I am trying to fall inside the business logic, I'm getting the following message:
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'.'
I spent a day struggling with the issue. And have no clue how to make it work.
What may be the reason and how I can fix it?
Here is the solution: https://docs.microsoft.com/en-us/aspnet/core/migration/22-to-30?view=aspnetcore-3.1&tabs=visual-studio#framework-reference
It appears that is should be fixed manually.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.