dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.15k stars 1.74k forks source link

Error boundary message does not display on mobile devices #9175

Closed ltemimi closed 2 years ago

ltemimi commented 2 years ago

Description

I have a MAUI Blazor project that uses the Error Boundary component . The error message displays correctly in Blazor server but not on mobile devices

image

Steps to Reproduce

1 Creat new dotnet Maui Bl;azor app 2 - Place an error boundary around the body tag

            <ErrorBoundary @ref="_errorBoundary">
                <ChildContent>
                   @Body
                </ChildContent>
                <ErrorContent Context="exception">
                    <ErrorBoundaryMessage
                        ErrorBoundary="@_errorBoundary"
                        Exception="exception">
                    </ErrorBoundaryMessage>
                </ErrorContent>
            </ErrorBoundary>
        </article>

3 - Simulate an error and observe it renders correctly on Blazor server but not on IOS or Androind

Version with bug

6.0.408 (current)

Last version that worked well

Unknown/Other

Affected platforms

iOS, Android

Affected platform versions

Windows server 2022

Did you find any workaround?

No

Relevant log output

just nothing is displayed on ios and android
MackinnonBuck commented 2 years ago

Hi @ltemimi, would you please provide a public, minimal repro project hosted as a GitHub repository that demonstrates the problem? Thanks!

ghost commented 2 years ago

Hi @ltemimi. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

MackinnonBuck commented 2 years ago

Another thing you could try is checking if the default error boundary works correctly.

danroth27 commented 2 years ago

The default ErrorBoundary seems to work fine in a .NET MAUI Blazor app:

image

ltemimi commented 2 years ago

Hi Many thanks for your help 1 - I am attaching the code to show the issue , the code has three projects a BlazorBase (bootstrapper) that is referenced by a Blazor Server project and a Dot net Maui blazor project. It can be used to show that that the error boundary works on blazor server but not in mobile devices.

To get the code bigger than 25 mb please use the link: https://1drv.ms/u/s!Ai1jsiYR5baCmpReUmQua3v6AztSpw?e=o1ZnJR

Code Android IOS BlazorServer
ltemimi commented 2 years ago

Are we saying I am stuck with the issue? Any suggestion work around?

danroth27 commented 2 years ago

Hi @ltemimi. The reason your ErrorBoundaryMessage is failing when running in .NET MAUI is because it has a dependency on the IHostingEnvironment service, which is only available when running in the context of an ASP.NET Core app. You can see this is the issue by checking dev tools console for the browser control (you can bring up the dev tools when running on Windows by hitting F12):

image

You'll need to refactor your ErrorBoundaryMessage component to not depend on this interface.