2

I get the infamous "Dialogs must be user-initiated" Security Exception when I try to print some stuff in Silverlight. As you can see, the dialog is as user-initiated as can be:

Silverlight printing "Dialogs must be user-initiated" Security Exception

John Papa couldn't help me much out neither, because I don't have any breakpoint set. Mr MSDN thinks it could also be that I'm just taking too long, but this is a demo application just as simple as can be.

Any ideas? I guess it's a Visual Studio quirk, maybe some extensions interfering, as things seems to work when I launch the application outside of it. I first thought maybe the Code Contracts are interfering with their IL weaving, but they are deactivated for this project.

Update: This is just a simple Silverlight application that runs locally from the file system. When I do "Start debugging", Visual Studio creates a hosting HTML file containing the Silverlight app in the Debug resp. Release folder of the project, launches the Internet Explorer with that HTML file and attaches the debugger to it.

Update 2: I also get the same error when I create a web project to host the Silverlight app and create a virtual directory for it on IIS.

I might also want to add that I don't have problems with printing in other Silverlight projects regardless of their hosting scenarios.

Update 3: I downloaded FireFox and it works, I don't get the error when I debug with it. So it seems to have to do with my IE8. I uploaded the solution:

http://dl.dropbox.com/u/10401470/Code/Demos/PrintingDemo.zip

I wonder if anyone can reproduce?

Anyone got an idea to which team I should file a bug report? Silverlight team? IE team? VS Debugger team?

herzmeister
  • 11,101
  • 2
  • 41
  • 51
  • It is an exception that's induced by the host. The BrowserService.GetBrowserHandle() method returns a Windows error, access denied. Though to troubleshoot of course. And hard to answer because you didn't describe your hosting scenario at all. – Hans Passant Nov 06 '10 at 15:43
  • @Hans Passant - I updated the question with more info about the "hosting scenario". – herzmeister Nov 06 '10 at 16:20
  • You didn't mention what happened when you let it create an ASP.NET web site instead. – Hans Passant Nov 06 '10 at 16:33
  • @Hans Passant - I get the same error, see update. – herzmeister Nov 06 '10 at 16:56
  • I dunno, I can't repro the exception. I use Win7, Firefox, VS2010, SilverLight4, UAC off. – Hans Passant Nov 06 '10 at 17:07
  • I was able to show up the print dialog box, but after hitting the print button, nothing happens. Then when I tried to click the print button for the second time, the print dialog box does not appear anymore. – Lance Nov 09 '11 at 08:45

4 Answers4

1

I've also experienced this strange behaviour. A standard button click event immediately invoking an OpenFileDialog. It would frequently generate the same error when being debugged but would eventually be coaxed in to working when the button is clicked several times.

However when built as a release (or perhaps simply by running the same Xap without a debugger attached to the browser) the problem would go away.

AnthonyWJones
  • 187,081
  • 35
  • 232
  • 306
  • So are these known bugs? If not, which team should be filed a bug report? Silverlight team? IE team? VS Debugger team? – herzmeister Nov 10 '10 at 22:47
1

Try to remove

if(SightPaleceListBox.Items.Count > 0)

Felix Yan
  • 14,841
  • 7
  • 48
  • 61
  • Thanks for taking a look, but no, I have tried that back then, and I still get the same error today. I'm gonna install SP1 for VS2010 these days though, maybe it will work then. – herzmeister Mar 31 '11 at 15:47
1

I'm able to reproduce this. You have handled the Click twice, once in XAML another time in code. See your MainPage.xaml

<Button x:Name="PrintButton"
   Content="Gotta print 'em!" Margin="8" 
   Click="PrintButton_Click" />

Don't feel bad about it. I did it last time through a misplaced Print inside a loop.

Chui Tey
  • 5,436
  • 2
  • 35
  • 44
  • wow, after all these years, that was it, thanks. That's what you get when you mindlessly copy and modify some sample code. Still a strange error though, because it's still executed directly in an event handler and thus it should merely print twice. – herzmeister Jan 07 '12 at 21:11
0

I had the same problem and found out that the reason was this following line:

cnvsMain.Children.Remove(PrintPagePlaceHolder);

cnvMain is on the page that the user pushed the Print button on (I was trying to remove it from that page in order to add it to the canvas that I was going to print).

My tip: try to comment rows one by one, until you find what row causes the problem. Than try to work around it.

Mr.Wizard
  • 24,179
  • 5
  • 44
  • 125
Keren
  • 81
  • 2
  • 10
  • Thanks, but I already had tried to remove everything to the minimal possible code in the sample project. I didn't try with the latest update though. – herzmeister May 02 '11 at 10:06