コンパイルエラー - 引数の型は「System.IO.FileStream」タイプをパラメータに割り当て可能ではありません「System.IO.Stream」
[HttpPost]
public async Task<IActionResult> Upload(string memberNumber, IFormFile file)
{
var uploadsFolderPath = Path.Combine(_host.WebRootPath, "uploads");
var fileName = Guid.NewGuid() + Path.GetExtension(file.FileName);
var filePath = Path.Combine(uploadsFolderPath, fileName);
using (var stream = new FileStream(filePath, FileMode.Create))
{
// Here's the compilation error
await file.CopyToAsync(stream);
}
var photo = new Photo(fileName);
var member = _unitOfWork.Members.GetByMemberNumber(memberNumber);
member.Photo = photo;
_unitOfWork.Complete();
return Ok(_mapper.Map<Photo, PhotoResource>(photo));
}
私はコンパイルエラーを取得しています画像を保存しようとしています.NETコア -
Argument type 'System.IO.FileStream' is not assignable to parameter type 'System.IO.Stream'
なぜですか?別のストリームライターを使うべきですか?パッケージがないとわからないのですか?
.csproj参照:
<ItemGroup>
<PackageReference Include="AutoMapper" Version="6.1.0" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="2.0.1" />
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.1" />
<PackageReference Include="Microsoft.AspNetCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.Cookies" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="1.1.2" />
<PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.3" />
<PackageReference Include="Microsoft.AspNetCore.StaticFiles" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="1.1.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer.Design" Version="1.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="1.1.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.2" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="Microsoft.VisualStudio.Web.BrowserLink" Version="1.1.2" />
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
のFileStreamメタデータのトップ:
#region Assembly System.IO.FileSystem, Version=4.0.1.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a//C:\Users\Leon\.nuget\packages\system.io.filesystem\4.3.0\ref\netstandard1.3\System.IO.FileSystem.dll#endregion
をインストールする私達にあなたの.csprojファイルの参照セクションを表示します。また、あなたが右クリックして 'new FileStream('呼び出し)のメタデータを表示し、コメントアウトした部分のテキストを新しいウィンドウの上部に表示したい場合は –
@ScottChamberlain質問を更新しました。ありがとうございます! – Lindeberg
Are – Volkan