Stream is not a valid resource file

  • Thread starter Thread starter Balu Kantu
  • Start date Start date
B

Balu Kantu

Guest
I am uploading a file to Api and trying to read the resource key and values. I am getting below exception when I try to read the file.

System.ArgumentException: Stream is not a valid resource file.
at System.Resources.ResourceReader._ReadResources()
at System.Resources.ResourceReader.ReadResources()
at System.Resources.ResourceReader..ctor(String fileName)



Below is the code which I tried.


[HttpPost]
public async Task<ActionResult> Post(IFormFileCollection files)
{
try
{
files = this.Request.Form.Files;
var tempFolder = Path.GetTempPath();

foreach (var formFile in files)
{
string fileName = ContentDispositionHeaderValue.Parse(formFile.ContentDisposition).FileName.Trim('"');
string filePath = Path.Combine(tempFolder, fileName);

if (formFile.Length > 0)
{
using (var stream = new FileStream(filePath, FileMode.Create))
{
await formFile.CopyToAsync(stream).ConfigureAwait(false);
}

var resReader = new ResourceReader(@filePath); // Throwing an exception.
}
}
}
catch (Exception ex)
{
throw;
}

return this.Ok("Success.");
}

Below is the request Uri and file.

RmRsq.png

I tried reading ResourceReader and facing an issue. Actually we need ResXResourceReader class and it is available in System.Windows.Forms and it is not available in .NET Core. Do we have any alternative for that class

Continue reading...
 
Back
Top