Another skill is "Dialogs must be user initiated." Silverlight Print Security Exception

I get the infamous "Dialogs must be user initiated." "Security exception" when I try to print some materials in Silverlight. As you can see, the dialog is initiated by the user in the same way as it can be:

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

John Papa could not help me , because I do not have a set of breakpoints. Mr MSDN believes that it may also be that I just took too long , but this demo application is as simple as it can be.

Any ideas? I assume this is Visual Studio quirk, maybe some extensions interfere, since everything works when I run the application outside. At first I thought that perhaps the code contracts interfere with their interweaving of IL, but they are deactivated for this project.

Update. This is just a Silverlight application that runs locally from the file system. When I do "Start Debugging", Visual Studio creates a hosting HTML file containing the Silverlight application in Debug resp. Release the project folder, launch Internet Explorer with this HTML file and attach a debugger to it.

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

I can also add that I have no printing problems in other Silverlight projects, regardless of their hosting scripts.

Update 3: I downloaded FireFox and it works, I do not get an error while debugging with it. So this seems to be related to my IE8. I downloaded the solution:

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

I wonder if anyone can reproduce?

Anyone got an idea, which team should I report the error to? Silverlight team? IE team? VS Debugger Team?

+2
source share
4 answers

I can reproduce this. You processed 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" /> 

Do not feel bad. I did this last time through unset printing inside a loop.

+1
source

I also experienced this strange behavior. The standard button click event immediately calls OpenFileDialog . It often generates the same error when debugging, but it will eventually be persuaded to work when the button is pressed several times.

However, when building as a release (or, perhaps, just running the same Xap without a debugger connected to the browser), the problem disappears.

+1
source

Try to remove

if(SightPaleceListBox.Items.Count > 0)

+1
source

I had the same problem and it turned out that the reason was the following line:

 cnvsMain.Children.Remove(PrintPagePlaceHolder); 

cnvMain is located on the page on which the user clicked the Print button (I tried to remove it from this page in order to add it to the canvas that I am going to print).

My advice: try commenting out the lines one by one until you find which line is causing the problem. Then try to get around this.

0
source

Source: https://habr.com/ru/post/1341772/


All Articles