From 9717f5c4e6566950d817f53b60db531a1c6fffa5 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 05:59:01 -0600 Subject: [PATCH 1/7] Exception handling in WinForms/WPF Blazor apps --- aspnetcore/blazor/hybrid/index.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 7e56a899c540..be5e2e701a6e 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -35,6 +35,28 @@ Blazor Hybrid exposes the underlying Web View configuration for different platfo Use the preferred patterns on each platform to attach event handlers to the events to execute your custom code. +## Exception handling in Windows Forms and WPF apps + +*This section only applies to Windows Forms and WPF Blazor Hybrid apps.* + +Create a callback for `UnhandledException` on the property. The following example uses a a [compiler directive](/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if) to display a that either alerts the user that an error has occurred or shows the error information to the developer. Log the error information in `error.ExceptionObject`. + +```csharp +AppDomain.CurrentDomain.UnhandledException += (sender, error) => +{ +#if DEBUG + MessageBox.Show(text: error.ExceptionObject.ToString(), caption: "Error"); +#else + MessageBox.Show(text: "An error occurred.", caption: "Error"); +#endif + + // Log the error information (error.ExceptionObject) +}; +``` + +> [!WARNING] +> Avoid exposing error information to users, which is a security risk. + ## Additional resources * From a6954c3f9f64a869a4e3d4d9e9d0027fae880308 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 06:01:13 -0600 Subject: [PATCH 2/7] Updates --- aspnetcore/blazor/hybrid/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index be5e2e701a6e..06301b298957 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -39,7 +39,7 @@ Use the preferred patterns on each platform to attach event handlers to the even *This section only applies to Windows Forms and WPF Blazor Hybrid apps.* -Create a callback for `UnhandledException` on the property. The following example uses a a [compiler directive](/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if) to display a that either alerts the user that an error has occurred or shows the error information to the developer. Log the error information in `error.ExceptionObject`. +Create a callback for `UnhandledException` on the property. The following example uses a [compiler directive](/dotnet/csharp/language-reference/preprocessor-directives/preprocessor-if) to display a that either alerts the user that an error has occurred or shows the error information to the developer. Log the error information in `error.ExceptionObject`. ```csharp AppDomain.CurrentDomain.UnhandledException += (sender, error) => From 5e786ac54de6300f65edc97572cd593790f62d25 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 06:12:08 -0600 Subject: [PATCH 3/7] Updates --- aspnetcore/blazor/hybrid/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 06301b298957..6246be32a370 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -35,7 +35,7 @@ Blazor Hybrid exposes the underlying Web View configuration for different platfo Use the preferred patterns on each platform to attach event handlers to the events to execute your custom code. -## Exception handling in Windows Forms and WPF apps +## Unhandled exceptions in Windows Forms and WPF apps *This section only applies to Windows Forms and WPF Blazor Hybrid apps.* From 745b80edf8636362e9d67dd81bcb47eb120cc1cc Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 07:11:33 -0600 Subject: [PATCH 4/7] Updates --- aspnetcore/blazor/hybrid/index.md | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 6246be32a370..5c9769efcb9d 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -5,7 +5,7 @@ description: Explore ASP.NET Core Blazor Hybrid, a way to build interactive clie monikerRange: '>= aspnetcore-6.0' ms.author: riande ms.custom: "mvc" -ms.date: 11/08/2022 +ms.date: 11/21/2022 uid: blazor/hybrid/index --- # ASP.NET Core Blazor Hybrid @@ -57,6 +57,23 @@ AppDomain.CurrentDomain.UnhandledException += (sender, error) => > [!WARNING] > Avoid exposing error information to users, which is a security risk. +## Globalization and localization + +.NET MAUI configures the and based on the device's ambient information. + + and other API in the namespace generally work as expected, along with globalization formatting, parsing, and binding that relies on the user's culture. + +When dynamically changing the app culture at runtime, the app must be reloaded to reflect the change in culture, which takes care of rerendering the root component and passing the new culture to rerendered child components. + +.NET's resource system supports embedding localized images (as blobs) into an app, but Blazor Hybrid can't display the embedded images in Razor components at this time. Even if a user reads an image's bytes into a using , the framework doesn't currently support rendering the retrieved image in a Razor component. + +[A platform-specific approach to include localized images](/xamarin/xamarin-forms/user-interface/images#local-images) is a feature of .NET's resource system, but a Razor component's browser elements aren't able to interact with such images. + +For more information, see the following resources: + +* [Xamarin.Forms String and Image Localization](/xamarin/xamarin-forms/app-fundamentals/localization/): The guidance generally applies to Blazor Hybrid apps. Not every scenario is supported at this time. +* [Blazor Image component to display images that are not accessible through HTTP endpoints (dotnet/aspnetcore #25274)](https://github.com/dotnet/aspnetcore/issues/25274) + ## Additional resources * From db9ae8cdd8e7027daa895bdd97b4fa13c640acdc Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 07:26:42 -0600 Subject: [PATCH 5/7] Updates --- aspnetcore/blazor/hybrid/index.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 5c9769efcb9d..1671700f5e85 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -59,6 +59,8 @@ AppDomain.CurrentDomain.UnhandledException += (sender, error) => ## Globalization and localization +*This section only applies to .NET MAUI Blazor Hybrid apps.* + .NET MAUI configures the and based on the device's ambient information. and other API in the namespace generally work as expected, along with globalization formatting, parsing, and binding that relies on the user's culture. @@ -67,7 +69,7 @@ When dynamically changing the app culture at runtime, the app must be reloaded t .NET's resource system supports embedding localized images (as blobs) into an app, but Blazor Hybrid can't display the embedded images in Razor components at this time. Even if a user reads an image's bytes into a using , the framework doesn't currently support rendering the retrieved image in a Razor component. -[A platform-specific approach to include localized images](/xamarin/xamarin-forms/user-interface/images#local-images) is a feature of .NET's resource system, but a Razor component's browser elements aren't able to interact with such images. +[A platform-specific approach to include localized images](/xamarin/xamarin-forms/user-interface/images#local-images) is a feature of .NET's resource system, but a Razor component's browser elements in a .NET MAUI Blazor Hybrid app aren't able to interact with such images. For more information, see the following resources: From 7b7df21f33e9b25017c0e498671ccdb71ff595d8 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:55:36 -0600 Subject: [PATCH 6/7] Update aspnetcore/blazor/hybrid/index.md Co-authored-by: Tanay Parikh --- aspnetcore/blazor/hybrid/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 1671700f5e85..103b5895b73b 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -47,7 +47,7 @@ AppDomain.CurrentDomain.UnhandledException += (sender, error) => #if DEBUG MessageBox.Show(text: error.ExceptionObject.ToString(), caption: "Error"); #else - MessageBox.Show(text: "An error occurred.", caption: "Error"); + MessageBox.Show(text: "An error has occurred.", caption: "Error"); #endif // Log the error information (error.ExceptionObject) From 09a91e759d1f60c47c69504426a8deb4e78e9550 Mon Sep 17 00:00:00 2001 From: Luke Latham <1622880+guardrex@users.noreply.github.com> Date: Mon, 21 Nov 2022 17:56:06 -0600 Subject: [PATCH 7/7] Updates --- aspnetcore/blazor/hybrid/index.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/aspnetcore/blazor/hybrid/index.md b/aspnetcore/blazor/hybrid/index.md index 103b5895b73b..128c5288306e 100644 --- a/aspnetcore/blazor/hybrid/index.md +++ b/aspnetcore/blazor/hybrid/index.md @@ -54,9 +54,6 @@ AppDomain.CurrentDomain.UnhandledException += (sender, error) => }; ``` -> [!WARNING] -> Avoid exposing error information to users, which is a security risk. - ## Globalization and localization *This section only applies to .NET MAUI Blazor Hybrid apps.*