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

How to register a global exception handler. Such as An equivalent to AppDomain.UnhandledException #45

Closed
gitfortee opened this issue Oct 9, 2017 · 6 comments

Comments

@gitfortee
Copy link

I am getting errors like

Error 1053: The service did not respond to the start or control request in a timely fashion.

Upon examining the 'Event Log', I could see

Faulting module path: C:\windows\system32\KERNELBASE.dll 

Exception code: 0xe0434352

This illustrates that I have not registered a global exception handler such as listening to the AppDomain.UnhandledException Or ThreadPool.UnhandledException

How do i register for these events ?

wrapping up the ServiceRunner<ServiceApp>.Run inside a try - catch does not capture the details of this 0xe0434352 exception. Looks like the catch block itself is not executed. This is the only try-catch block i have. The code is not swallowing any exceptions..

try
{
	ServiceRunner<ServiceApp>.Run(config =>
	...
}
catch (Exception ex)
{
	var path = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, "logs\\service-error.txt");
	File.WriteAllText(path, e.StackTrace);
}
@ragnarol
Copy link
Contributor

Have you tried:

AppDomain.CurrentDomain.UnhandledException += (sender, eventArgs) => { }

@gitfortee
Copy link
Author

@ragnarol AppDomain.CurrentDomain.UnhandledException is this feature available in core 1.1? I guess it is not. My application built on .net core 1.1

@ragnarol
Copy link
Contributor

HI @gitfortee , no it was introduced in .net core 2.

Anyway I think you should close this issue and make this question in Stackoverflow, is probably the right place for it as it is not related to this library.

Said that, your other question about the installation of the service maybe related to your version of .net core as well, I have only tried with 2,0

@gitfortee
Copy link
Author

@ragnarol understood.. can you please post some code if you have that goes inside the AppDomain.CurrentDomain.UnhandledException ? There is a ExceptionObject property. Im not sure how to extract information out of it.

@gitfortee
Copy link
Author

gitfortee commented Oct 11, 2017

Ok. this is what i found out.. the service started working once i upgraded to .net core version 2.0 !!! To recap, even with .net core version 1.1, there was no difficulty in running the application stand-alone or as a service with a "local system" account. The service started to fail only when i configured it to run using a service account..

However, with the same service account and after upgrading my projects and libraries to core version 2.0, the service is working fine.. strange.!!

@PeterKottas do you like this be documented somewhere? please let me know

@PeterKottas
Copy link
Owner

Hi guys, sorry for late reply. Thanks for getting my back @ragnarol ! Appreciated. Well this is a rather small lib so there's no great support for legacy sdk versions. That would obviously require some extra effort with testing and all and it just makes more sense to keep this up to date with Microsoft and hope people will do the same. SDK updates after all are fairly painless these days. It's a good point so I am glad it's here in the issue but overall, I don't think we need an extra docs about this. If you want, you can PR readme and add a small foot note there. But the general rule would be to keep the SDK updated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants