You also encounter this if you run an Application on a Scheduled Task in Non-Interactive mode.
As soon as you show a Dialog it throws the error:
Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application.
You can see its a MessageBox causing the problem in the stack trace:
at System.Windows.Forms.MessageBox.ShowCore(IWin32Window owner, String text, String caption, MessageBoxButtons buttons, MessageBoxIcon icon, MessageBoxDefaultButton defaultButton, MessageBoxOptions options, Boolean showHelp)
If you're running your app on a Scheduled Task send an email instead of showing a Dialog.