Unhandeled exception not fire when there is fatal exception
Hi, Unhandeled exception not fire when there is fatal exception And make the http query.
In debugger it works only when it syronous https call.. I comment all code in realse and add code that write to log and is not working. File.WriteAllText(@"D:\1.txt", "Test"); That mean it not reach in handele exception in realse mode?
Thanks,
using Autofac;
using GssdDesktopClient.API.Imp;
using GssdDesktopClient.Maui.Helpers;
using GssdDesktopClient.Maui.Startup;
namespace GssdDesktopClient.Maui
{
public partial class App : Application
{
public App()
{
InitializeComponent();
//MainPage = new AppShell();
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
}
private async void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
try
{
if (!string.IsNullOrEmpty(LoginConfigurations.GetInstance().SessionToken))
{
var container = new Bootstrapper().Bootstrap();
IAutomationApiClient automationApiClient = container.Resolve<IAutomationApiClient>();
var res = await automationApiClient.PostLogOut($"{LoginConfigurations.GetInstance().Portal}/api/GSPortal/PostLogOut/false", LoginConfigurations.GetInstance().SessionToken);
}
}
catch (Exception)
{
}
}
public static Window window;
protected override Window CreateWindow(IActivationState activationState)
{
window = new Window(new AppShell());
return window;
}
}
}
Developer technologies | .NET | .NET MAUI
-
Anonymous
2024-02-02T07:55:32.6566667+00:00 Do you use AppDomain.UnhandledException Event (System) | Microsoft Learn to get exception? Can you share a specific fatal exception that you want to get? Which line have exceptions in above code?
-
Dani_S • 4,501 Reputation points
2024-02-02T09:05:16.1666667+00:00 - I used AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; to get the exception.
2.The app crach in one of the pages and the code in handler of UnhandledException is not done, not catch.
3.Does the code i provided is correct ?
-
Anonymous
2024-02-06T07:42:01.7066667+00:00 You add the
AppDomain.CurrentDomain.UnhandledException
in theApp.xaml.cs
, Can you add this code in the other pages that will raise exceptions. -
Dani_S • 4,501 Reputation points
2024-02-06T09:07:24.5+00:00 I added the AppDomain.CurrentDomain.UnhandledException in hosted page and view code behaind in ctor and is not hit.
-
Dani_S • 4,501 Reputation points
2024-02-06T09:16:19.1433333+00:00 The exception:
-
Dani_S • 4,501 Reputation points
2024-02-06T09:16:51.8133333+00:00 The exception:
-
Dani_S • 4,501 Reputation points
2024-02-10T10:46:57.28+00:00 Does it works in your side?What wrong with my code?
-
Dani_S • 4,501 Reputation points
2024-02-11T07:02:53.8+00:00 Is it connected to this code? public static Window window; protected override Window CreateWindow(IActivationState activationState) { window = new Window(new AppShell()); return window; }
-
Anonymous
2024-02-15T05:23:09.5566667+00:00 No, I comment out following code, it could run normally in my side. Which package does the following code come from? Determine whether these packages can run on MAUI.
if (!string.IsNullOrEmpty(LoginConfigurations.GetInstance().SessionToken)) { var container = new Bootstrapper().Bootstrap(); IAutomationApiClient automationApiClient = container.Resolve<IAutomationApiClient>(); var res = await automationApiClient.PostLogOut($"{LoginConfigurations.GetInstance().Portal}/api/GSPortal/PostLogOut/false", LoginConfigurations.GetInstance().SessionToken); }
Please add a breakpoint in
var container = new Bootstrapper().Bootstrap();
line, check which line have issues. -
Dani_S • 4,501 Reputation points
2024-02-15T10:06:37.6233333+00:00 The breakpoint hit but when I made in debug is working but without debuging is not working. Do I need to make the query syncronos ?
-
Dani_S • 4,501 Reputation points
2024-02-15T10:37:35.8666667+00:00 In addition the code use Autofac + HttpClientHandler to make post request
-
Anonymous
2024-02-19T07:49:00.4833333+00:00 The breakpoint hit but when I made in debug is working but without debuging is not working. Do I need to make the query syncronos ?
Try to add a Task.Delay for testing. Is that working?
await Task.Delay(500).ContinueWith(t => { MainThread.InvokeOnMainThreadAsync(() => { // invoke your code });
-
Dani_S • 4,501 Reputation points
2024-02-19T09:36:27.9266667+00:00 In debugger it works only when it syronous https call. I tried your code not help in realse. I comment all code in realse and add code that write to log and is not working. File.WriteAllText(@"D:\1.txt", "Test"); That mean it not reach in handele exception in realse mode? What to do ?
-
Dani_S • 4,501 Reputation points
2024-02-19T10:26:41.4566667+00:00 To test i throw exception: throw new Exception("Test");
-
Dani_S • 4,501 Reputation points
2024-02-21T06:35:34.6233333+00:00 Any answer ?
-
Anonymous
2024-02-22T09:32:35.77+00:00 Can you open your csproj file, copy the release part of code here?
-
Dani_S • 4,501 Reputation points
2024-02-22T09:37:59.54+00:00 ........
-
Dani_S • 4,501 Reputation points
2024-02-22T09:56:30.24+00:00 <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <TargetFrameworks>net8.0-android;net8.0-ios;net8.0-maccatalyst</TargetFrameworks> <TargetFrameworks Condition="$([MSBuild]::IsOSPlatform('windows'))">$(TargetFrameworks);net8.0-windows10.0.19041.0</TargetFrameworks> <!-- Uncomment to also build the tizen app. You will need to install tizen by following this: [https://github.com/Samsung/Tizen.NET]() --> <!-- <TargetFrameworks>$(TargetFrameworks);net6.0-tizen</TargetFrameworks> --> <OutputType>Exe</OutputType> <RootNamespace>GssdDesktopClient.Maui</RootNamespace> <UseMaui>true</UseMaui> <SingleProject>true</SingleProject> <ImplicitUsings>enable</ImplicitUsings> <!-- Display name --> <ApplicationTitle>GssdDesktopClient.Maui</ApplicationTitle> <!-- App Identifier --> <ApplicationId>com.companyname.gssddesktopclient.maui</ApplicationId> <ApplicationIdGuid>8cbb5874-850c-4837-a4c2-5ccf37d9b99b</ApplicationIdGuid> <!-- Versions --> <ApplicationDisplayVersion>1.0</ApplicationDisplayVersion> <ApplicationVersion>1</ApplicationVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'ios'">14.2</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'maccatalyst'">14.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'android'">21.0</SupportedOSPlatformVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</SupportedOSPlatformVersion> <TargetPlatformMinVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'windows'">10.0.17763.0</TargetPlatformMinVersion> <SupportedOSPlatformVersion Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) == 'tizen'">6.5</SupportedOSPlatformVersion> <PackageCertificateThumbprint>C01BA45666762F3615CF6813AEB4DC4B1919541D</PackageCertificateThumbprint> <AppxPackageSigningEnabled>True</AppxPackageSigningEnabled> </PropertyGroup> xml <ItemGroup> <!-- App Icon --> <MauiIcon Include="Resources\AppIcon\appicon.png" /> <!-- Splash Screen --> <MauiSplashScreen Include="Resources\AppIcon\appiconfg.png" BaseSize="128,128" /> <!-- Images --> <MauiImage Include="Resources\Images\*" /> <MauiImage Update="Resources\Images\dotnet_bot.svg" BaseSize="168,208" /> <!-- Custom Fonts --> <MauiFont Include="Resources\Fonts\*" /> <!-- Raw Assets (also remove the "Resources\Raw" prefix) --> <MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" /> </ItemGroup> <ItemGroup> <None Remove="Pages\MainPage.xaml.cs~RF526042b.TMP" /> <None Remove="Resources\Fonts\segoeui.ttf" /> <None Remove="Resources\Fonts\telerikcontrolsicons.ttf" /> <None Remove="Resources\Fonts\TelerikFont.ttf" /> <None Remove="Resources\Fonts\telerikfontexamples.ttf" /> <None Remove="Resources\Images\back.png" /> <None Remove="Resources\Images\cancel.png" /> <None Remove="Resources\Images\clear.png" /> <None Remove="Resources\Images\copy.png" /> <None Remove="Resources\Images\dashboard.png" /> <None Remove="Resources\Images\download.png" /> <None Remove="Resources\Images\eye_blue.png" /> <None Remove="Resources\Images\false_status.png" /> <None Remove="Resources\Images\file.png" /> <None Remove="Resources\Images\folder.png" /> <None Remove="Resources\Images\gs_logo.png" /> <None Remove="Resources\Images\history.png" /> <None Remove="Resources\Images\inscan.gif" /> <None Remove="Resources\Images\in_process.png" /> <None Remove="Resources\Images\login_background.png" /> <None Remove="Resources\Images\logs.png" /> <None Remove="Resources\Images\refresh.png" /> <None Remove="Resources\Images\refresh_dashboard.png" /> <None Remove="Resources\Images\sidedrawer.png" /> <None Remove="Resources\Images\small_wave.png" /> <None Remove="Resources\Images\treeview_drive.png" /> <None Remove="Resources\Images\treeview_file.png" /> <None Remove="Resources\Images\treeview_folder.png" /> <None Remove="Resources\Images\true_status.png" /> <None Remove="Resources\Images\unallowed_file.png" /> <None Remove="Resources\Images\upload.png" /> <None Remove="Resources\Images\vcheck.png" /> <None Remove="Resources\Images\waiting.gif" /> <None Remove="Resources\Images\wave.png" /> <None Remove="Resources\Images\xcheck.png" /> <None Remove="Resources\Raw\configuartionsFile.xml" /> <None Remove="Resources\Raw\externalApplications.xml" /> <None Remove="Resources\Raw\log4net.config" /> <None Remove="ViewModels\LoginViewModel.cs~RF666ffa12.TMP" /> </ItemGroup> <ItemGroup> <PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" /> <PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" /> <PackageReference Include="CommunityToolkit.Maui" Version="7.0.0" /> <PackageReference Include="System.Management" Version="7.0.2" /> <PackageReference Include="Telerik.UI.for.Maui" Version="6.5.0" /> <PackageReference Include="Microsoft.Extensions.Logging.Log4Net.AspNetCore" Version="7.0.0" /> <PackageReference Include="Autofac" Version="7.1.0" /> <PackageReference Include="DotNetZip" Version="1.16.0" /> </ItemGroup> <!-- Windows --> <ItemGroup Condition="$(TargetFramework.Contains('-windows')) == true"> <PackageReference Include="WindowsAPICodePack" Version="7.0.4" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\AutomationClient.API\GssdDesktopClient.API.csproj" /> <ProjectReference Include="..\GssdDesktopClient.Shared\GssdDesktopClient.Shared.csproj" /> </ItemGroup> <ItemGroup> <Compile Update="AppShellMainPage.xaml.cs"> <DependentUpon>AppShellMainPage.xaml</DependentUpon> </Compile> </ItemGroup> <ItemGroup> <MauiFont Update="Resources\Fonts\segoeui.ttf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </MauiFont> <MauiFont Update="Resources\Fonts\telerikcontrolsicons.ttf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </MauiFont> <MauiFont Update="Resources\Fonts\TelerikFont.ttf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </MauiFont> <MauiFont Update="Resources\Fonts\telerikfontexamples.ttf"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </MauiFont> </ItemGroup> <ItemGroup> <MauiXaml Update="AppShellMainPage.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> <MauiXaml Update="Pages\LoginPage.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> <MauiXaml Update="Pages\MainPage.xaml"> <Generator>MSBuild:Compile</Generator> </MauiXaml> l> </ItemGroup> <ItemGroup> <None Update="Resources\Raw\certificate.pfx"> <CopyToOutputDirectory>Always</CopyToOutputDirectory> </None> </ItemGroup> </Project>
-
Anonymous
2024-02-23T09:36:42.9166667+00:00 Did this issue just happen in windows release mode? If so, For your scenario, it is recommended to open a support ticket for this. Please contact our paid phone support at MS Support. You will get 1:1 support on that.
-
Dani_S • 4,501 Reputation points
2024-02-23T13:03:37.3766667+00:00 But why in release the unhandle exception handler not hit? Does it work in your side? I publish it as an exe.
-
Dani_S • 4,501 Reputation points
2024-02-25T10:09:02.6733333+00:00 I looked in internet: https://stackoverflow.com/questions/72455467/how-do-you-create-a-global-error-handling-for-a-maui-app => FirstChanceException is working this the right way ? AppDomain currentDomain = AppDomain.CurrentDomain; currentDomain.FirstChanceException += CurrentDomain_FirstChanceException;
-
Dani_S • 4,501 Reputation points
2024-02-25T12:24:07.02+00:00 But why in release the unhandle exception handler not hit. I need to logout in this case. please help?
-
Dani_S • 4,501 Reputation points
2024-02-25T12:26:11.6166667+00:00 BTW:FirstChanceException hit in realse but is not the case.
-
Dani_S • 4,501 Reputation points
2024-02-28T09:33:03.51+00:00 Can you please help ?
-
Dani_S • 4,501 Reputation points
2024-02-28T09:33:27.55+00:00 Can you please help?
-
Anonymous
2024-02-28T09:51:07.1666667+00:00 Is above code not working after installing released .exe file? I cannot reproduce this issue in my side; it is better to open a support ticket for this.
-
Dani_S • 4,501 Reputation points
2024-02-28T10:01:19.7266667+00:00 No.code not working after installing released .exe file bou why? Also withou debugging is not working. Is it bug?
-
Dani_S • 4,501 Reputation points
2024-03-03T09:04:50.5033333+00:00 Can you please refere to my ouestion?
Why FirstChanceException is ht in relase mode but UnhandledException not ?
-
Dani_S • 4,501 Reputation points
2024-03-24T11:01:45.73+00:00 can you please check with sample code in the end of in this link:
https://github.com/dotnet/maui/issues/21007
why UnhandledException not work.
Add the code where is neccesary?
Sign in to comment
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
1 deleted comment
Comments have been turned off. Learn more