This code works fine in my WP8 app:
void App_UnhandledException(object sender, UnhandledExceptionEventArgs args)
{
string appName;
string appVersion;
var xmlReaderSettings = new XmlReaderSettings
{
XmlResolver = new XmlXapResolver()
};
using (var xmlReader = XmlReader.Create("WMAppManifest.xml", xmlReaderSettings))
{
xmlReader.ReadToDescendant("App");
appName = xmlReader.GetAttribute("Title");
appVersion = xmlReader.GetAttribute("Version");
}
WAMS_EXCEPTIONLOG wamsel = new WAMS_EXCEPTIONLOG
{
appNameAndVersion =
string.Format("{0} {1}", appName,
appVersion),
ExceptionMsg =
args.ExceptionObject.Message,
InnerException =
args.ExceptionObject
.InnerException.ToString(),
ExceptionToStr =
args.ExceptionObject.ToString(),
dateTimeOffsetStamp =
DateTimeOffset.UtcNow
};
await MobileService.GetTable<TASLS_WAMS_EXCEPTIONLOG>().InsertAsync(wamsel);
}
...but in my complementary Windows store app, several classes and class members are unrecognized, to wit:
XmlResolver
XmlXapResolver
args.ExceptionObject
(not to mention the fact that await is not allowed, and adding "async" to the event handler causes the assignment of the event handler to "go red")...
So, to get back to the main point: How can I achieve the same functionality I'm getting with my WP8 app with my Windows Store app?
Let me first address your issues:
args.Exception
.async void
in the method signature but you must keep in mind that the method will be called in "fire and forget" mode, i.e. the app won't wait for the asynchronous method to complete.This shouldn't be a problem if you setargs.Handled = true
and thus prevent the app from closing.Your fixed event handler should look like this:
You should also check if
args.Exception.InnerException
is null, before callingToString()
on it.