I just launched an application on the store, and I'm realizing by checking my bug reports that a generic snippet I took from MSDN is crashing on Lumia 520 devices. Can I prevent 52x owners from downloading this application?
[EDIT]
Here's the code:
// Use the back sensor as the default sensor
CameraSensorLocation defaultSensor = CameraSensorLocation.Back;
// If the user already configured the front sensor, use it (true=front, false=back)
if ((bool)appSettings["sensor"]) { defaultSensor = CameraSensorLocation.Front; frontMode.Visibility = System.Windows.Visibility.Visible; }
// Let's check which sensors exist
var availableLocations = PhotoCaptureDevice.AvailableSensorLocations;
// There comes the bug
var captureRes = PhotoCaptureDevice.GetAvailableCaptureResolutions(defaultSensor);
Here's the exception (which contains no inner exception):
Exception message:
The request is not supported. (Exception from HRESULT: 0x80070032)
Stacktrace:
at Windows.Phone.Media.Capture.PhotoCaptureDevice.GetAvailableCaptureResolutions (CameraSensorLocation sensor)
at Vixl.Pages.ShootPage.<openCamera>d__c.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.CompilerServices.AsyncMethodBuilderCore.<ThrowAsync>b__0(Object state)
GetAvailableCaptureResolutions being an async method, the relevant part is only the first level exception message at the top of the stack. The sensor is the rear sensor, not the front one. I'll investigate in this specific error.
The Lumia 520 is a 512 MB device, so it's far more likely that your app is crashing because of a memory issue than that there's something specific to just the Lumia 520.
As far as I know, the only control you have in terms of who can download your app are the requirements you can define for the application in the application manifest and they all deal with things like NFC, front/rear camera and so on.
What kind of exception is being thrown that's causing the application to crash? Can you post the stack trace and relevant code?
Related
In my web application, I have a custom configuration file which I want to monitor for changes and update the application settings immediately. So I am using IOptionsMonitor<T> to get this done. It works well.
As per the documentation the method that gets called when configuration file changed is wired up like below.
var data = _serviceProvider.GetRequiredService<IOptionsMonitor<MySettings>>();
data.OnChange(OnReaderSettingOptionsChanged);
Within the OnReaderSettingOptionsChanged() method, I do some validations and there is a need to throw an exception on an edge case so that application shouldn't continue.
The problem is when I throw the exception, I expect to see a error on browser (dev mode with details or normal error otherwise). But it's not showing because according to this exception gets fired in another thread.
So, is there another way for me to get this across to browser?
I'm setting up a pretty simple ASP.Net Core (2.2) MVC Web App. I want to be able to see any application errors (500s) and what caused them so it seems like Application Insights is the place to look.
If I go into Application Insights / Failures (Operations Tab - see screenshot below), I'm able to see a graph/count of all the 500 errors. I can click on "DRILL INTO" button and see a lof of the details (Event Time, Request Name, etc...) but cannot seem to get any details on the actual cause of the error / line number.
Basically, I have the exact same problem as this person:
Azure Monitor / Application Insights not showing stack trace for errors
(my screenshots look identical).
When I drill down to the exception details, I get something like this:
I'm want to get something like this:
I did see info on adding Application Insights via Nuget to my solution and putting
services.AddApplicationInsightsTelemetry();
into the Startup/ConfigureServices method.
I also see that you can look at Kudu logs, etc... but I really want this all to be easily accessible in Application Insights.
Any suggestions?
OK - I think I solved my own problem. Turns out I had added Serilog a while back (sort of forgot about that) and it was capturing all the errors before getting to AI. When I removed the Serilog configuration code from Program.cs and Startup.cs, the application exceptions started showing up in Application Insights / Failures along with the full Call Stack. Thanks for your suggestions!
A 500 Internal server error suggests you are looking for the stack trace to identify what went wrong and where. No code has been provided in your example but you will need to surround your code with a try catch and then log the exception to get the stack trace or you can use the TelemetryClient as below:
var telemetry = new TelemetryClient();
...
try
{ ...
}
catch (Exception ex)
{
// Set up some properties:
var properties = new Dictionary <string, string>
{{"Game", currentGame.Name}};
var measurements = new Dictionary <string, double>
{{"Users", currentGame.Users.Count}};
// Send the exception telemetry:
telemetry.TrackException(ex, properties, measurements);
}
Further information can be found at Microsoft
According to Exception handling for Windows Runtime apps in C# or Visual Basic MS recommends:
"If your app crashes, don't attempt to display any info to the user that describes the specifics of the crash even if the app lifetime state lets you do so."
[This recommendation is for WinRT apps, there seems to be not recommendation for UWP. I assume we are supposed to treat them the same.]
Can someone explain the rationale behind this?
The MS UWP apps do follow this rule. I have had Mail, Translator, Calculator, the Store app, ... abort without any feedback on crash or at restart.
I personally find it annoying when apps simply disappear without any hint.
The "little Watson" solution of displaying error info on the next start feels weird to me. Both behaviors doe not conform with common user expectations
What is wrong with in App_UnhandledException:
display a MessageDialog with error details,
and then rethrow the exception to force the app to crash?
Rare cases where the app is in such a bad state that it cannot display a MessageDialog (which I have never experienced) are no reason not to try.
I understand that in App_UnhandledException the app might be in a undefined/fragile state and one should minimize the code executed here. But we do already trace exceptions here and track them via HockeyApp. Why not notify the user?
If crash error notifications are helpful for users depends on the app and the target audience. For enterprise apps I know from long experience that error notifications (even with deep technical infos) are definitely helpful. Users are often able to circumvent problems and keep working with defective apps without even contacting support (while support was automatically made aware of the problem). The value for consumer oriented apps is debatable. I assume many users will stop entering 0 as a divisor when seeing an Arg_OverflowException right after entering data or remember having unplugged their cable modem when seeing a http_client exception.
No technical reasons against notifying users about unexpected exceptions at UWP app crashes or showing exception details were stated. If such notifications may be helpful for end users depends on the app and the target audience.
Here a code sample notifying the user from within App.UnhandledExcetion or at next app start:
Protected Overrides Async Sub OnLaunched(e As Windows.ApplicationModel.Activation.LaunchActivatedEventArgs)
...
If _notifyUserAboutCrash = NotifyUserAboutCrash.OnNextStart Then
Await ProblemReporter.NotifyLastExToUserIfExisting()
End If
...
End Sub
Private Async Sub App_UnhandledException(sender As Object, e As UnhandledExceptionEventArgs) Handles Me.UnhandledException
If _isAborting Then Return
Dim unhandledEx = New Exception(e.Message, e.Exception)
e.Handled = True
Trace.Error($"Unexpected exception: {unhandledEx.InnerException.ToString}")
Await Trace.CompleteAsync()
Try
ProblemReporter.SaveAsLastException(unhandledEx)
HockeyClient.Current.TrackException(unhandledEx.InnerException)
HockeyClient.Current.Flush()
Catch ex As System.Exception
Trace.Error(ex)
End Try
If _notifyUserAboutCrash = NotifyUserAboutCrash.OnError Then
Await ProblemReporter.NotifyExceptionToUserViaMessageDialogAsync(unhandledEx)
End If
Await ForceAppCrashAsync(unhandledEx)
End Sub
Private Shared Async Function ForceAppCrashAsync(unhandledEx As Exception) As Task
Trace.Fatal("!!! aborting")
Await Trace.CompleteAsync()
_isAborting = True
ExceptionDispatchInfo.Capture(unhandledEx.InnerException).Throw()
End Function
For the complete code and some gotchas see my post Global Error Handling for UWP-Apps.
I've run over a somewhat little problem over the week. The error message upfront this is about:
[30-Dec-2012 15:19:32] PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
I think it is because my error handler (see below for details) is turning any error into an exception. I might should prevent that in case there is no stack frame.
Is there an easy way to find out if there is any stack frame or not in PHP?
Details:
On one of my websites I've got an error handler running that is turning every error into an exception, the common ErrorException to be precise.
I introduced it some time ago because the site is mainly legacy code and I wanted to have any issue result in an exception I can finally "catch" in a streamlined fashion an exception handler and give the request a stop.
I put this into class of it's own, the handler is registered and also in parallel an output buffer is opened to catch the output up until the exception is thrown. Basically code like this:
// register output buffering
$r = ob_start(array($this, 'handleBuffer'));
// register error handler
$this->_originalErrorHandler = set_error_handler(array($this, 'handleError'));
// register exception handler
$this->_originalExceptionHandler = set_exception_handler(array($this, 'handleException'));
This worked all fine and dandy until I decided to add another output buffering class into the mix. Just one that catches as well all output and then can do some "post production" on the website, including checking for HTML problems (yes, it's all a bit legacy so actually this is a bit duck-taped, I know). That also worked very fine btw. however not when I made a mistake in the new component:
[30-Dec-2012 15:19:32] PHP Fatal error: Exception thrown without a stack frame in Unknown on line 0
This is basically my problem. Is there an easy way to prevent getting these errors? I somewhat know why the error is given but I'm not so entirely sure so it's hard for me to really circumvent the problem. I tried to release the new output buffer before the script enters the new shutdown phase because I thought this would cause this. But this didn't make it.
Your problem indicates that you are using an EOL (End Of Life) version of PHP (specifically PHP < 5.3.0), which means it's no longer supported. This issue comes from throwing an exception where no strack frame exists and as such the old engine did not know how to handle those exceptions properly.
This can be due to a couple of different reasons. Some of the most common ones are as follows:
You threw an exception from inside an error handler or exception handler.
You threw an exception from inside a destructor.
You threw an exception from inside a callback (like an output buffering callback function).
Here's an example that demonstrates your problem under some of those circumstances...
function myErrorHandler($errno, $errstr, $errfile, $errline)
{
throw new ErrorException($errstr, $errno, 0, $errfile, $errline);
}
function myExceptionHandler($exception) {
echo "We got an exception with message: '{$exception->getMessage()}'";
}
function myCallBack($contents) {
trigger_error('ohnoes!'); // You can't throw an error from the output buffer callback function in older versions of PHP < 5.3
}
class Foo {
public function __destruct() {
trigger_error('ohnoes!'); // You can't throw an error from a destructor in older versions of PHP < 5.3
}
}
set_error_handler('myErrorHandler');
set_exception_handler('myExceptionHandler');
The above code would cause you to see the fatal error you described here...
ob_start("myCallBack");
... and here...
$foo = new foo;
This problem has been fixed in PHP >= 5.3.0 so you should not see this issue if you were using the most current version of PHP.
The simplest fix is to upgrade your PHP. If that is not an option you must consider these facts that you can not throw exceptions where PHP does not expect them to be thrown (in callback functions, error handlers, exceptions handlers, etc... -- which are actually all considered to be callbacks to PHP).
The other thing is you should not be turning every error into an exception in this way. If what you are doing is as the code I supplied demonstrates (i.e. throwing an exception from inside the error handler -- thus turning every error into an exception) then you are going to cause yourself a lot of pain and with virtually no benefit. PHP errors are not meant to be handled. They are meant to inform the client of a problem (the client being the person writing the PHP code), or potential problem. Handling the error itself is not as simple as turning every error into an exception and then handling that exception, because not every error should be exceptional. For instance, E_NOTICE level errors have no place in exception handling. They are primarily used to notify you of a potential for a bug, not that there is necessarily something buggy with your code and not to mention that most of them can't even be handled easily in user-space code (they mostly require re-factoring the code itself). I strongly advice against this poor practice.
We have a large e-business application server that is out of our control, we can not modify it in any way shape or form. The company behind this application server will also not modify it to our customers requirements. This is due to the fact that they see us as a competitor and they do not wish the customer to use our application as a front end to their application.
Our desktop application uses web services to communicate with this application server and each login from the desktop occupies a user slot on the server. The application server offers no functionality that enables us to figure out if a user slot is taken or not. The best solution would be for us to develop an application that sits in the middle of the application server and our desktop client, this application would manage the allocation and deallocation of user slots and the problem is solved. This solution has be declined as the customer does not want to install our application on the e-business application server as that would void the user support of said e-business server, the alternative would be an extra server but that is something they don't want to deal with.
Which leaves us with the solution that our desktop application has write access to a shared folder. Each desktop application has a UID and we use that UID together with the user slot id and create a file UID.UserSlotId.locked. This would mean that each time a connection is made the desktop application would need to check this shared location and make sure they are not about to use a UserSlotId that is taken.
Now I now that the locked file is a terrible solution but the customer has requested this and no matter how much we inform them that this will never be a water tight solution they still want to go ahead. They are under the assumption that a 98% solution is a good solution. So what can the StackOverflow community offer in the way of advice with dealing with such a file locking system?
Open the lock file in Write mode and keep it open while the application uses a slot.
private static void TakeFistUnusedLock(FileStream[] currentLock)
{
for (int i = 1; i < 5; i++)
{
try
{
var fs = File.OpenWrite(Path.Combine(Path.GetTempPath(), "DbLock", i.ToString() + ".lock"));
currentLock[i - 1] = fs;
Console.WriteLine("Got lock " + i);
break;
}
catch (Exception) { }
}
}
I tested like this
FileStream[] currentLock = new FileStream[5];
var path = Path.Combine(Path.GetTempPath(), "DbLock");
DirectoryInfo di = new DirectoryInfo(path);
di.Create();
TakeFistUnusedLock(currentLock);
TakeFistUnusedLock(currentLock);
TakeFistUnusedLock(currentLock);
currentLock[1].Dispose(); // release lock 2
TakeFistUnusedLock(currentLock);
output was
Got lock 1
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
Got lock 2
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
Got lock 3
A first chance exception of type 'System.IO.IOException' occurred in mscorlib.dll
Got lock 2
Instead of keeping the currentLock array you only store one lock per application. You need to store the opened FileStream to make sure the file stays open in write mode. To release the lock you dispose the stored FileStream, then the write lock on the file is released.
This method ensures that the locks are released even if your application crashes.