This post is the result of my experiments with handling unexpected errors in UWP-Apps.
For my approach about tracing see Tracing for UWP-Apps

It is debatable if showing information about unexpected exceptions to users is good idea. I have had Mail, Translator, Calculator, the Store app and other UWP-Apps 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 app start feels weird to me. Both behaviors doe not conform with common user expectations.

If crash error details can be helpful for end users depends on the app type 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 might have been made aware of the problem automatically in the background…).

Options to inform users about unexpected exceptions are:

Never notify users about exceptions.

Show dialog in App.UnhandledException

Show dialog on next app start.

Show exception details like Message and HResult

Show “Sorry…” only.

This following code sample implements the main options, configurable via _notifyUserAboutCrash.

Exception details

The exception details available via UnhandledExceptionEventArgs are more detailed in debug mode then in release mode. Sometimes e.Message contains more details then e.Exception.Message. In debug mode it contains the start of the StackTrace.

I make a distinction between tracing the program flow and variable values for developer usage and logging unexpected exceptions and important status messages for system management.

None of the tools available fulfilled all these requirement to my liking. Thus I wrote a little class Trace with the following features:

Stores traces in alternating text files in ApplicationData.

Short static trace methods.

Trace levels Verbose, Debug, Info, Time, Status, Warning, Error, Fatal, Off
The level “Status” is intended to filter messages for logging errors and important status messages like started and stopped. This level is missing in many tracing frameworks and leads to either flooding logs intended for system management with info messages or not logging important status messages.

Inject trace location via compiler generated parameter values like CallerMemberName and CallerLineNumber. These point to the correct source code location even in release. mode (when the app was compiled with the .NET Native toolchain.

Buffer traces in a TPL BatchBlock to improve performance when writing to storage.

CyclicBuffer to allow to trace the last n messages on error.
Experimental feature only. Have not used it in production yet. Don’t know if it still works.

Since Windows 10 Anniversary Update one can view files like trace files in the users \AppData via the App File Explorer of the Device Portal:

View trace files on device using Device Portal

]]>https://petermeinl.wordpress.com/2016/07/09/tracing-for-uwp-apps/feed/0pmeinlUWPErrors Abb6 App File ExplorerQuirks with date and number formats in UWP Apps and Windows 10https://petermeinl.wordpress.com/2016/06/06/quirks-with-date-and-number-formats-in-uwp-apps-and-windows-10/
https://petermeinl.wordpress.com/2016/06/06/quirks-with-date-and-number-formats-in-uwp-apps-and-windows-10/#respondMon, 06 Jun 2016 14:37:08 +0000http://petermeinl.wordpress.com/?p=2017Continue reading →]]>In Windows 10 users can configure several languages, a region, a Regional format and additionally several on-screen keyboards (OSK) in different languages. How to switch between OSK and their handling of region-specific decimal separators is not immediately obvious. UWP apps do by design ignore the Regional format configured by the user and there is a debate if developers should work around this.

Don’t Make the User Think

When displaying dates and numbers and designing data entry it is important to make intuitively clear what the data format is. We must avoid making users think to determine if a number is a day or a month or if a . (dot) is a decimal or a thousand separator.

To avoid confusion with dates spell out the month name instead of using numbers. It is common misconception that using a specific separator (e.g. / instead of .) clarifies what is the day and what is the month.
Display June 7, 2019 instead of 07/06/2019

To avoid confusion with decimal separators it may be helpful to display decimals even it they are always 00:
Display 5,300.00 instead of 5,300

On-screen number pads should by default show the decimal separator for the language the user selected. E.g. show a . (dot) with a US keyboard and a , (comma) with a German keyboard.

To make working with dates and numbers intuitively easy we should honor the Windows Regional format the user has configured.

Using Multiple Keyboards

The keyboard selection i.a. influences if a . (dot) or a , (comma) is shown on number pads, see InputScope (Number, for Windows Phone) – you can always long-tap to get a different decimal separator. To experience the difference add two keyboards for languages using different decimal separators e.g. English and German.

Switching between OSKs works differently in Win10 Mobile and other Win10 versions. In Win10 Mobile you can long-tap on &123 or simply swipe on the space bar. Please note that in some InputScopes you cannot switch the OSK because neither &123 nor the space-bar are shown. Here you need to first show a complete OSK, e.g. by tapping Cortana search, switch the OSK there and come back to the app now showing a different decimal separator on the reduced keyboard.

Regional Format in UWP Apps

UWP apps by default are supposed to only honor the active language and the keyboard selected and to ignore region and regional format when formatting dates and numbers.

If the user for instance configures English (US) as primary language, Thailand as region and German as regional format, see screenshots below, the UWP app will unexpectedly display dates and numbers in US format.

Win10 Mobile

Win10 Professional

I see the following options to handle such constellations:

Accept the UWP default behavior.
Dates and numbers are formatted according to the language only.
Ingore the users regional format selection..

Use the Region selected by the user via
PrimaryLanguageOverride = UserProfile.GlobalizationPreferences.HomeGeographicRegion
This usage was not intended by MS and it may have side effects the user dislikes, like not being able to use the Region he really is located in to localize search results etc. or laborious working with the Windows Store.
At first I used this approach in my app Travel Currencies but did not like it.

Use the Regional format selected by the user
via the workaround described below.

Digital nomads need robust and flexible gear to perform their work duties. Because I frequently get asked for good traveling stuff this post recommends hardware and software for the Windows ecosystem and other things helpful for working while traveling.

For some items redundancy is mandatory because the whole business of a digital nomad relies on uninterrupted availability of computer and telecommunications gear:

2 notebooks.

2 power supplies: To reduce the risk of forgetting the power supply: One power supply always stays at home the 2nd one always is in the carry-on bag. Only buy original power supplies, don’t get tempted by way cheaper copies!

2 cloud storage providers.

2+ ways to connect to the internet.

2+ credit cards.

Computers and Accessories

Flexible, sturdy and expandable work horse. Sadly only available with the dreadful 16×9 (1920×1080) display aspect ratio. I5 CPUs are generally powerful enough. Consider upgrading RAM and SSD with 3rd party components to reduce cost (not as easy as with older ThinkPad models though). Make sure you get a 2015+ model with dedicated TrackPoint buttons. The 2014 model severely crippled the usefulness of the TrackPoint with buttons in the TrackPad only. If you want something more portable and fancy at the cost of flexibility go for the X1 Carbon (2015+).

Screen has a nice 3×2 aspect ratio for usage as tablet in portrait mode. Can replace the ThinkPad as a notebook if need arises.

Alternatively: Surface Pro 3 + Surface Pro 4(!) Type Cover
A Surface Pro 3 is good enough. If you can get one for a good price, add a Surface Pro 4(!) Type cover. The version 4 type cover key spacing and general typing feeling is much better than with version 3 and it does not hide TaskBar buttons when connected.

The Microsoft Surface Book might be a viable alternative as primary notebook but it is extremely expensive. While it is really nice machine I prefer the ThinkPad/Surface combination especially because I like the ThinkPad TrackPoint better than any touch pad.

Microsoft Lumia 640 Dual-SIM LTEInstall Win10 via the Windows Insider app. Good enough phone. Good size. So cheap that it is not a real problem if stolen or lost. Get the dual SIM version to conveniently use local SIMs. Get LTE for using it as mobile hotspot (backup for internet connectivity).

Cheaper than the Oasis version but with the same quality screen. Better than the Paperwhite because of separate paging buttons. The Origami cover is very good for reading at a table. No need for the 3G version: one can easily download via the phone hotspot. The additional neoprene cover protects against drops.

I don’t really fancy the G-Shock look but this watch is not bulky, still sturdy and very practical. Features world time, alarms that are loud enough for me, solar charging, auto light via turning wrist, auto time sync, water resistant to 200m, displays day of week, …Pimp it with the way more comfortable resin band (Casio Part No 10323536) of the expensive GW-5000 version. I bought a couple from PacParts shipped to Germany via MyUs.com.

Surprisingly good and practical smart-watch. I bought it only to test custom tiles for my Travel Currencies app but found that I really like it.

Because it was not available in Germany yet I bought mine from Amazon.com, shipped to Germany via MyUs.com. Total cost 186€: Band 2: 174.99$, MyUscharges: 34.78$, customs: 6.63€, VAT: 33.22€, FedEx charges: 12.50€.

SW Tools

Install and update multiple commonly used tools (like FileZialla and Notepad++) at once. Nice clean unobtrusive UI. Get the pro version for automatic updates and to support the developers. Shame on Adobe for no longer allowing them to update Acrobat reader!

Password safe. Includes Win 10 mobile version. They have an informative post about good passwords.

Microsoft file-based Backup “Windows 7 Backup and Restore”

Fortunately Microsoft reintroduced the Windows 7 file-based(!) backup with Windows 10 (they had discarded it with Windows 8x). It may not have the nicest UI but works way better and more reliable than all commercial alternatives (especially Acronis True Image) I tried. It still is difficult to find: search for “Windows 7 Backup and Restore”. I am not talking about the Image Backup which is available for Win7, 8+ and 10!

To plan and monitor trips. You can simply forward many booking confirmation emails (e.g. from Agoda) to plans@tripit.com and they get parsed and automatically added to your trip. The 3rd party MyTrips Windows Phone app is way better than the app from TripIt.

Local telephone number that reachesyou via Skype. For example I have a German Skype number that my parents (who don’t have internet) can dial from their telephone to reach me worldwide in Skype on all my devices.

Digital nomads need robust and flexible gear to perform their work duties. Because I frequently get asked for good traveling stuff this post recommends hardware and software for the Windows ecosystem and other things helpful for working while traveling.

For some items redundancy is mandatory because the whole business of a digital nomad relies on uninterrupted availability of computer and telecommunications gear:

2 notebooks.

2 power supplies: To reduce the risk of forgetting the power supply: One power supply always stays at home the 2nd one always is in the carry-on bag. Only buy original power supplies, don’t get tempted by way cheaper copies!

2 cloud storage providers.

2+ ways to connect to the internet.

2+ credit cards.

Computers and Accessories

Flexible, sturdy and expandable work horse. Sadly only available with the dreadful 16×9 (1920×1080) display aspect ratio. I5 CPUs are generally powerful enough. Consider upgrading RAM and SSD with 3rd party components to reduce cost (not as easy as with older ThinkPad models though). Make sure you get a 2015+ model with dedicated TrackPoint buttons. The 2014 model severely crippled the usefulness of the TrackPoint with buttons in the TrackPad only. If you want something more portable and fancy at the cost of flexibility go for the X1 Carbon (2015+).

Screen has a nice 3×2 aspect ratio for usage as tablet in portrait mode. Can replace the ThinkPad as a notebook if need arises.

Alternatively: Surface Pro 3 + Surface Pro 4(!) Type Cover
A Surface Pro 3 is good enough. If you can get one for a good price, add a Surface Pro 4(!) Type cover. The version 4 type cover key spacing and general typing feeling is much better than with version 3 and it does not hide TaskBar buttons when connected.

The Microsoft Surface Book might be a viable alternative as primary notebook but it is extremely expensive. While it is really nice machine I prefer the ThinkPad/Surface combination especially because I like the ThinkPad TrackPoint better than any touch pad.

Install Win10 via the Windows Insider app. Good enough phone. Good size. So cheap that it is not a real problem if stolen or lost. Get the dual SIM version to conveniently use local SIMs. Get LTE for using it as mobile hotspot (backup for internet connectivity).

Cheaper than the Oasis version but with the same quality screen. Better than the Paperwhite because of separate paging buttons. No need for the 3G version: one can easily download via the phone hotspot. The Origami cover is very good for reading at a table. The additional neoprene cover protects against drops.

I don’t really fancy the G-Shock look but this watch is not bulky, still sturdy and very practical. Features world time, alarms that are loud enough for me, solar charging, auto light via turning wrist, auto time sync, water resistant to 200m, displays day of week, …Pimp it with the way more comfortable resin band (Casio Part No 10323536) of the expensive GW-5000 version. I bought a couple from PacParts shipped to Germany via MyUs.com.

Surprisingly good and practical smart-watch. I bought it only to test custom tiles for my Travel Currencies app but found that I really like it.

Because it was not available in Germany yet I bought mine from Amazon.com, shipped to Germany via MyUs.com. Total cost 186€: Band 2: 174.99$, MyUscharges: 34.78$, customs: 6.63€, VAT: 33.22€, FedEx charges: 12.50€.

SW Tools

Install and update multiple commonly used tools (like FileZialla and Notepad++) at once. Nice clean unobtrusive UI. Get the pro version for automatic updates and to support the developers. Shame on Adobe for no longer allowing them to update Acrobat reader!

Password safe. Includes Win 10 mobile version. They have an informative post about good passwords.

Microsoft file-based Backup “Windows 7 Backup and Restore”

Fortunately Microsoft reintroduced the Windows 7 file-based(!) backup with Windows 10 (they had discarded it with Windows 8x). It may not have the nicest UI but works way better and more reliable than all commercial alternatives (especially Acronis True Image) I tried. It still is difficult to find: search for “Windows 7 Backup and Restore”. I am not talking about the Image Backup which is available for Win7, 8+ and 10!

To plan and monitor trips. You can simply forward many booking confirmation emails (e.g. from Agoda) to plans@tripit.com and they get parsed and automatically added to your trip. The 3rd party MyTrips Windows Phone app is way better than the app from TripIt.

Local telephone number that reachesyou via Skype. For example I have a German Skype number that my parents (who don’t have internet) can dial from their telephone to reach me worldwide in Skype on all my devices.

Digital nomads need robust and flexible gear to perform their work duties. Because I frequently get asked for good traveling stuff this post recommends hardware and software for the Windows ecosystem and other things helpful for working while traveling.

For some items redundancy is mandatory because the whole business of a digital nomad relies on uninterrupted availability of computer and telecommunications gear:

2 notebooks.

2 power supplies: To reduce the risk of forgetting the power supply: One power supply always stays at home the 2nd one always is in the carry-on bag. Only buy original power supplies, don’t get tempted by way cheaper copies!

2 cloud storage providers.

2+ ways to connect to the internet.

2+ credit cards.

Computers and Accessories

Flexible, sturdy and expandable work horse. Sadly only available with the dreadful 16×9 (1920×1080) display aspect ratio. I5 CPUs are generally powerful enough. Consider upgrading RAM and SSD with 3rd party components to reduce cost (not as easy as with older ThinkPad models though). Make sure you get a 2015+ model with dedicated TrackPoint buttons. The 2014 model severely crippled the usefulness of the TrackPoint with buttons in the TrackPad only. If you want something more portable and fancy at the cost of flexibility go for the X1 Carbon (2015+).

Screen has a nice 3×2 aspect ratio for usage as tablet in portrait mode. Can replace the ThinkPad as a notebook if need arises.

Alternatively: Surface Pro 3 + Surface Pro 4(!) Type Cover
A Surface Pro 3 is good enough. If you can get one for a good price, add a Surface Pro 4(!) Type cover. The version 4 type cover key spacing and general typing feeling is much better than with version 3 and it does not hide TaskBar buttons when connected.

The Microsoft Surface Book might be a viable alternative as primary notebook but it is extremely expensive. While it is really nice machine I prefer the ThinkPad/Surface combination especially because I like the ThinkPad TrackPoint better than any touch pad.

Microsoft Lumia 640 Dual-SIM LTEInstall Win10 via the Windows Insider app. Good enough phone. Good size. So cheap that it is not a real problem if stolen or lost. Get the dual SIM version to conveniently use local SIMs. Get LTE for using it as mobile hotspot (backup for internet connectivity).

Cheaper than the Oasis version but with the same quality screen. Better than the Paperwhite because of separate paging buttons. No need for the 3G version: one can easily download via the phone hotspot. The Origami cover is very good for reading at a table. The additional neoprene cover protects against drops.

I don’t really fancy the G-Shock look but this watch is not bulky, still sturdy and very practical. Features world time, alarms that are loud enough for me, solar charging, auto light via turning wrist, auto time sync, water resistant to 200m, displays day of week, …Pimp it with the way more comfortable resin band (Casio Part No 10323536) of the expensive GW-5000 version. I bought a couple from PacParts shipped to Germany via MyUs.com.

Surprisingly good and practical smart-watch. I bought it only to test custom tiles for my Travel Currencies app but found that I really like it.

Because it was not available in Germany yet I bought mine from Amazon.com, shipped to Germany via MyUs.com. Total cost 186€: Band 2: 174.99$, MyUscharges: 34.78$, customs: 6.63€, VAT: 33.22€, FedEx charges: 12.50€.

SW Tools

Install and update multiple commonly used tools (like FileZialla and Notepad++) at once. Nice clean unobtrusive UI. Get the pro version for automatic updates and to support the developers. Shame on Adobe for no longer allowing them to update Acrobat reader!

Password safe. Includes Win 10 mobile version. They have an informative post about good passwords.

Microsoft file-based Backup “Windows 7 Backup and Restore”

Fortunately Microsoft reintroduced the Windows 7 file-based(!) backup with Windows 10 (they had discarded it with Windows 8x). It may not have the nicest UI but works way better and more reliable than all commercial alternatives (especially Acronis True Image) I tried. It still is difficult to find: search for “Windows 7 Backup and Restore”. I am not talking about the Image Backup which is available for Win7, 8+ and 10!

To plan and monitor trips. You can simply forward many booking confirmation emails (e.g. from Agoda) to plans@tripit.com and they get parsed and automatically added to your trip. The 3rd party MyTrips Windows Phone app is way better than the app from TripIt.

Local telephone number that reachesyou via Skype. For example I have a German Skype number that my parents (who don’t have internet) can dial from their telephone to reach me worldwide in Skype on all my devices.

Private files should only be stored in the cloud being encrypted via a key controlled and known by the user solely (= end-to-end encryption). Transport encryption and encryption in the cloud provided by storage providers are not sufficient here.

Attack Surface

The safety of encryption depends on good passwords. Passwords are good if they are not only strong but also easy to use. For an interesting discussion about better passwords see Toward Better Master Passwords.

Some cloud storage providers like Tresorit support automatic end-to-end encryption out of the box. For an overview and reviews of cloud storage providers and VPN services see Cloudwards. Many widely used services like DropBox and the deeply in Windows integrated OneDrive are sadly lacking this support. For these one can use additional encryption tools like:

boxcryptor: Good commercial tool.CryptSync: Free open source tool based on 7-zip encryption.
Allows decrypting files even without CrypSync using 7-zip apps.

Without any form of automated end-to-end cloud encryption one should encrypt private data manually before storing it in the cloud, which is inconvenient. Some tools for this are: 7-zip passwords, TrueCrypt 7.1a or VeraCrypt.

Data I classify as “paranoid” should not be stored in the cloud at all. Some of it should never be stored electronically at all, like critical login credentials or banking TANs.

OneNote uses a custom synchronization mechanism over OneDrive. Thus non of the automatic encryption approaches work with it. One either looses synchronization or must use inconvenient notebook or section passwords

In addition to end-to-end cloud encryption one should encrypt local drives because your files (or at least remnants of them) are stored there in decrypted form. Win10 does automatically enable BitLocker for all internal drives (not for removable drives like SD cards!) but for convenience stores the key under your Microsoft account in OneDrive, see onedrive.live.com/recoverykey. To regain control of your keys one can disable and reenable BitLocker and not select “Save to your Microsoft account”. By this you loose the convenience of MS taking care of your keys and are responsible yourself: if you loose your key you loose your data! On Win10 mobile one must manually enable encryption via Settings, System, Device Encryption. Win10 mobile does not allow to encrypt removable drives and there seems to be no way to gain control of your keys, see here.

CloudCryptor experimental app

When using cloud storage one has to trust storage providers and/or creators of encryption tools. Thus it would be nice to roll your own end-to-end encryption. To get a feeling for this I wrote the experimental app CloudCryptor (download code). Beware! I have limited expertise in security and my experimental code is buggy and unsafe (e.g. does not use the IV properly). While the abstraction level of the .NET crypto API is nicely high, the strength of a crypto solution depends on selecting the right crypto methods and using them correctly for which one needs solid crypto expertise. My resumé: Don’t write your own encryption apps if you are not a security expert!

Encrypting the password

To avoid having to enter the password frequently it can be stored locally. CloudCryptor stores the password encrypted via ProtectedData (= NET API of the Windows Data Protection API (DPAPI)). DPAPI derives its encryption key form the login credentials of the current Windows user.

Configuration UI

Notice the DPAPI encrypted password in the config file!

Configuration UI

Cross-device usage

End-to-end encrypted files can be used across heterogeneous devices like desktops, tablets and phones. BoxCryptor offers a Win10 mobile app and there are 7-zip apps with password support for Win10 mobile. In my CloudCryptor experiments I used “file type associations” to trigger decryption on the Windows Phone.

Cross-Device Usage

]]>https://petermeinl.wordpress.com/2016/03/25/thoughts-about-cloud-encryption/feed/2pmeinlAttack SurfaceCloudCryptoArchitectureCloudCryptorUICrossDeviceIntegrationHow to completely clean install Windows 10 on a UEFI PChttps://petermeinl.wordpress.com/2015/09/06/how-to-really-do-a-clean-install-of-windows-10-on-a-uefi-pc/
https://petermeinl.wordpress.com/2015/09/06/how-to-really-do-a-clean-install-of-windows-10-on-a-uefi-pc/#commentsSun, 06 Sep 2015 10:04:48 +0000http://petermeinl.wordpress.com/?p=1533Continue reading →]]>With Windows 10 I generally do recommend to simply upgrade which preserves your apps (modern and desktop), data and settings. In contrast to previous Windows versions the Win 10 upgrade is robust and has worked fine for me on several machines, so I consider a clean install not being worth the time needed.

With my Surface Pro 3 (SP3) however I wanted to do a clean install, including removing Windows 8.1 partitions no longer needed. A Win 10 upgrade from Win 8.1 left my Surface with the partitions shown in the picture below. I could not find any reliable information on which partitions are safe to delete.

Change boot order
on SP3 to USB -> SSD
via holding volume-up key while releasing the power button.

Boot from USB
which automatically starts Win 10 setup.

Delete all partitions
from within Win 10 setup.

Complete Win 10 install.

Run Windows update.

Change boot order back to SSD only.

Obstacles

USB sticks for booting with UEFI must be formatted as FAT32. The current standard Microsoft tools allow to create NTFS only. Thus I used Rufus.

My SP3 would not boot from a USB stick.I worked around that using Advanced Startup Options:Later I found that I had disabled “Boot from side USB” in UEFI advanced security settings. After enabling this my SP3 boots fine from USB.

Some Hints

My Win 10 did activate automatically. When asked for a license key during setup I always skipped. I do not know if the Win 8 license key was stored in UEFI or if it was stored in my MS account because of a previous Win 10 upgrade.

After Setup and before installing any Windows updates wireless internet worked already. To speed-up updates I re-plugged my USB Ethernet adapter which promptly caused Win 10 to install a driver for it.

Device manager showed many device drivers missing. I simply ran Windows update. After all updates were installed, device manager no longer showed any drivers missing. There was no need to manually download an install the Surface Win 10 driver package.

Processing Patterns

We can generally choose between event-driven processing, polling loops and timers. With loops it is important to implement a delay to prevent consuming a complete CPU when idle. For optimal reactivity such delays should be cancellable, ex by candellationToken.WaitHandle.WaitOne(someTimeSpan).

Event-driven processing. Generally preferred.

Polling loop in a dedicated thread. OK for a single worker loop.

Polling loop in tasks. With many worker loops use a task for each.

Poll using a timer. No need for a dedicated thread or task to prevent blocking the main thread.

I am using a new Channel instance for each WCF call. This improves robustness against communication problems and against “The socket connection was aborted” exceptions after a client idle time > 10 min (= default ReceiveTimeout) with netTcpBinding even when using InstanceContextMode=PerCall.