Object not set to an instance on OnPause() - xamarin

I get 'Object not set to an instance' error on my App every time my App request permission to access READ_PHONE_STATE and ACCESS_FINE_LOCATION in OnPause() method. I didn't write code to request permission, the App request permission automatically.
As soon as the permission dialog shows up, OnPause() method gets triggered and the error occurs on this line : base.OnPause();
protected override void OnPause()
{
base.OnPause(); //error occurs here
}
How can i solve this issue ?
What's the best method of requesting all the relevant permissions ? And how can I you handle this method in OnResume() and OnPause() methods.

I finally found the issue. The problem was caching on my phone. Clicking Ctrl+F5, forced the Application to clear all the cache. Rebuild didn't work. After clicking Ctrl+F5, the permission dialogs showed without triggering the OnPause function - and object not set to an instance error message disappeared.

Related

How to properly handle exception inside controller?

I am trying to upload a file. And if it throws an exception I don't want to see the "whoops" page. Instead it will go back the previous page with a message. This is what I tried,
try {
$data = Excel::toArray(new Import, request('file'));
} catch (\Exception $e) {
return back()->withErrors("an exception occured");
}
But it still gives me the whoops page whenever any exception occurs.
How to solve it?
Laravel 5.0 and up ships with an error handler at app/Exceptions/Handler.php. Here you can define a handler for any exception in your application. This way you don't need to add extra error handling in your controllers.
All information can be found in the documentation: https://laravel.com/docs/6.x/errors#the-exception-handler
I don't believe you will be able to catch/handle a Fatal Error. The script has stopped and is unrecoverable at this point. A shutdown handler is running as the script is shutting down. This is being handled by a shutdown function via register_shutdown_function.
Illuminate\Foundation\Bootstrap\HandleExceptions#handleShutdown will check to see if there was an error and if it was fatal and then pass a Symfony\Component\Debug\Exception\FatalErrorException to its own handler as an example.

How can I disable alert message when the request is fail?

In some request, I need to change this alert to be somewhere on the screen, so how I can disable the default behavior when failing the request the alert show up by abp.message.error and I need to disable it and use another way.
You can send all exception details to the client easily. There's a setting for this purpose.
...
using Abp.Web.Configuration;
...
public override void PreInitialize()
{
Configuration.Modules.AbpWebCommon().SendAllExceptionsToClients = true;
}
...
References:
Related Aspnet Boilerplate document
Throwing user friendly exception forum post
Related GitHub commit
Yet another related GitHub issue
Besides, you can disable exception handling for an application service or for an application service method. Just use [DontWrapResult] attribute for that.
public interface ITestAppService : IApplicationService
{
[DontWrapResult]
DoItOutput DoIt(DoItInput input);
}
See the related Aspnet Boilerplate docs

How to clear database entries on browser close in jsf?

In our application which makes
use of JSF/PrimeFaces, Spring and Hibernate once a user logs in, we set a flag in the DB until the user logs out from the application or the session expires. The problem is, we need to clear this flag in the DB even when he simply closes the browser without proper logout. To acheieve this, I have already tried jquery $window.unload and $window.bind functions which actually invokes some JS function which is associated with <p:remoteCommand> which in turn invokes a managed bean method to clear the DB. However, I later came to know this is not reliable and while testing also we saw the event was not firing consistently. How can I achieve the DB cleanup anyway?
Listening on browser close is not reliable. You can use beforeunload event for that, but this is not supported on every webbrowser the world is aware of and even disableable/spoofable/hackable by the enduser. Then we're not talking about the race condition during firing the ajax request: would the ajax request arrive in its entirety right before the browser is closed? More than often this is not the case and the browser close wins over the ajax request.
Just listen server side on session expiration instead.
#WebListener
public class MyHttpSessionListener implements HttpSessionListener {
#Override
public void sessionCreated(HttpSessionEvent event) {
// NOOP.
}
#Override
public void sessionDestroyed(HttpSessionEvent event) {
HttpSession session = event.getSession();
// Do your job here.
// ...
}
}
Note that this is also invoked when you explicitly invoke ExternalContext#invalidateSession() (or HttpSession#invalidate()) during programmatic logout.

Catching server side ajax handling errors in browser

Let's say I have some ajax based component, whose handler in server throws for some reason an exception (e.g. programming error, can't access database). And basically server responds with internal server error or some such. How can I catch this situation in browser and display for examplen an error message somewhere.
When user clicks this link, the server will show an error page and the browser should detect based on http status code that something went wrong and somehow to react to it.
new AjaxLink<Link>("link") {
public void onClick(AjaxRequestTarget target) {
throw new RuntimeException();
}
}
See org.apache.wicket.settings.IExceptionSettings#getAjaxErrorHandlingStrategy.
There is an example of this at http://www.wicket-library.com/wicket-examples/ajax/links (failure and exception links).
Normally, Wicket Ajax classes like AjaxFallbackLink for example, have a method
updateAjaxAttributes(AjaxRequestAttributes attributes)
where you can register error handlers, that execute javascript within the browser.
Override this method, create an AjaxCallListener and call
AjaxCallListener listener = new AjaxCallListener();
listener.onFailure(ADD_JAVASCRIPT_TO_EXECUTE_HERE);
attributes.getAjaxCallListeners().add(listener);
see the documentation of
org.apache.wicket.ajax.attributes.AjaxCallListener.getFailureHandler(Component component)

C# windows service crashes without hitting catch block

I have a c# windows service that crashes without logging almost everyday after running for a few hours. Recently I added catch blocks to literally every method and still it doesn't help. Since I am using asynchronous callbacks on MSMQ, I guess there could be some multi-threading issues, but I have no clear clue. Any insight into this problem will be very helpful. Here is the pseudo code:
public MyService : ServiceBase
{
onStart()
{
try
{
someQueue.BeginReceive()
}
catch(Exception e)
{
log error and throw
}
}
void someQueue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
{
try
{
//process the message
}
catch(Exception e)
{
//log
}
finally
{
someQueue.Refresh()
someQueue.BeginReceive();
}
}
}
You can check Event Viewer to know the reason of Service getting stopped.
Open start menu and start Event Viewer, in application section you'll find the error
I know years passed since this request. But I got the same issue and no solution worked for me, other than the following.
In my case, the Event Viewer was not giving any details about the crash, and all user rights were ok.
the issue was a line of code in the OnStart method:
Debugger.Launch();
It was trying to launch the debugger, but that was not installed on that server. As such, it never completed and no exception was caught by my code.
Got rid of that, and it started working.

Resources