4

I try to debug my silverlight application that contain OpenFileDialog.ShowDialog() call - and i get error exception about security ( "SecurityException was unhandled by user code : Dialogs must be user-initiated" )

When i run the application without debug - i don't get this exception.

But i must run it in debug mode because i need to see that i doing the right thing with the file that the customer choose ...

How can i run it with in debug mode ?

Thanks for any help.

Yanshof
  • 9,659
  • 21
  • 95
  • 195

3 Answers3

2

If you are, and I assume you are, initiating the ShowDialog() call with a button click, Silverlight has some strange heuristics for determining if the action was user initiated.

It does work with debugging, but if you're stepping though the code from the Button_Click to the ShowDialog(), it seems to think that because of the delay, it is not a user initiated action.

To get around this, I'd recommend using logging instead of stepping through to debug the application. Silverlight is notorious for throwing these exceptions when trying to debug the ShowDialog() calls.

*EDIT

Silverlight does not use the Click() event to determine whether the button was user initiated. It uses a host of heuristics to determine it correctly including a timer (which is why debugging fails)

Ray Booysen
  • 28,894
  • 13
  • 84
  • 111
2

This issue has been logged at Microsoft:

http://connect.microsoft.com/VisualStudio/feedback/details/597430/debugging-of-code-between-the-user-initiated-entry-point-and-call-for-the-savefiledialog-openfiledialog-showdialog-method-lead-to-the-dialogs-must-be-user-initiated-exception#details

Just put the breakpoint after .ShowDialog().

Dre
  • 153
  • 7
0

make sure that when you open the dialog it is triggered by a button click. This is done for security reasons.

Edit

Apparently there is a bug in IE that can cause this error to raise even when user initiated

http://forums.silverlight.net/forums/p/208282/491053.aspx

Another knack on the "Dialogs must be user-initiated" Security Exception in Silverlight printing

Community
  • 1
  • 1
Luc Bos
  • 1,722
  • 1
  • 13
  • 24