unexpected behavior for await call in while header when compiling in release mode / with flag optimize=true #132
Description
Hi, first, thanks for a nice blazor plugin.
Using Blazor wasm app (NET standard 2.1) and the BlazorFileReader in the following code snippet (shortened, in my app it is divided into a .razor file and a .razor.cs file but shortened and put together here for the sake of simplicity):
@inject Blazor.FileReader.IFileReaderService fileReaderService
@using Blazor.FileReader;
<div class="ml-2">
<input type="file" @ref="InputElement" @onchange="FilesSelected" multiple accept=".txt,.csv" />
</div>
@code {
ElementReference InputElement;
[Parameter] public List<string> FileContent { get; set; }
async Task FilesSelected()
{
foreach (var file in await fileReaderService.CreateReference(InputElement).EnumerateFilesAsync())
{
using (Stream stream = await file.OpenReadAsync())
{
FileContent = await ReadLinesAsync(stream, Encoding.UTF8);
}
}
}
public async Task<List<string>> ReadLinesAsync(Stream stream, Encoding encoding)
{
using (var reader = new StreamReader(stream, encoding))
{
string line;
var result = new List<string>();
while ((line = await reader.ReadLineAsync()) != null)
{
result.Add(line);
}
return result;
}
}
}
Running this code locally (Ctrl+F5 in visual studio 2019 16.6 preview) reads any text file just fine. But when uploading this to Azure, it reads the correct number of lines but each line is empty. (as in string.Empty
).
I do not know if this is a problem with BlazorFileReader or with blazor/azure....(?)
EDIT: Realizing it is probably not in the BlazorFileReader I will try to ask on SO...
EDIT2: I realized it probably has to do with StreamReader.ReadLineAsync()
in "release" mode.