Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unexpected behavior for await call in while header when compiling in release mode / with flag optimize=true #132

Closed
erikthysell opened this issue May 28, 2020 · 7 comments
Labels
duplicate This issue or pull request already exists possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself

Comments

@erikthysell
Copy link

erikthysell commented May 28, 2020

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.

@Tewr
Copy link
Owner

Tewr commented May 29, 2020

hello!

I never got around to/managed reproduce this when I last heard about it, I think its a blazor bug, has something to do with the linker.
Try the solution in #97 in the meantime and see if that works for you. Seems like the exact same problem.

@Tewr Tewr added possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself duplicate This issue or pull request already exists labels May 30, 2020
@Tewr
Copy link
Owner

Tewr commented Jun 5, 2020

I can reproduce this consistently. The workaround in #97 is still working.
I'm working on a minimalistic repro project to submit a bug to the blazor team. Seems like a really tricky bug. I'm no longer sure it is related to the linker. The workaround can be implemented side-by side, even in the same class, and there is no problem.

I'm more thinking the Optimization step in release mode. Perhaps something is wrong the async invocation and the c# generated from the .razor file.

@Tewr Tewr added the bug Something isn't working label Jun 5, 2020
@Tewr
Copy link
Owner

Tewr commented Jun 5, 2020

Confirmed, it's the optimizer. Problem is still present with linker turned off. Problem is no longer present when optimizer is turn off:

  <PropertyGroup>
    <Optimize>false</Optimize>
  </PropertyGroup>

@Tewr Tewr removed the bug Something isn't working label Jun 5, 2020
@Tewr
Copy link
Owner

Tewr commented Jun 5, 2020

I have a full minimal repro example. This is definitely a framework bug in the optimizer, not related to this library.

@erikthysell
Copy link
Author

Thanks a lot. The workaround is indeed working.

@Tewr
Copy link
Owner

Tewr commented Jun 19, 2020

This has been corrected in runtime but is not yet released, I'll keep this open until then

@Tewr Tewr changed the title Reading text file works locally but not in Azure unexpected behavior for await call in while header when compiling in release mode / with flag optimize=true Jul 19, 2020
@Tewr
Copy link
Owner

Tewr commented Sep 30, 2020

Fixed in Blazor 5rc1

@Tewr Tewr closed this as completed Jun 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists possible-blazor-issue This possibly a problem in the blazor framework that needs a workaround or a bugfix in blazor itself
Projects
None yet
Development

No branches or pull requests

2 participants