'System.ObjectDisposedException: Cannot access a disposed object. C#

FileController.cs

public IActionResult GetFileByName(string name)
  {
    return _file.GetFile(name);
  }

FileRepository.cs

  public FileStreamResult GetFile(string name)
  {
  
    string path = "C:\\"
    FileInfo fileInfo = new fileInfo(path);
    using FileStream fileStream = fileInfo.Open(FileMode.Open);
    return new FileStreamResult(fileStream, "application/pdf")
                {
                    FileDownloadName = "bill.pdf"
                };
}

////In Response exception message ###System.ObjectDisposedException: Cannot access a disposed object.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source