locked
[UWP]Access denied exception from HRESULT 0x80070005 (E_ACCESSDENIED) On Printing only. RRS feed

  • Question

  • Hello,

    I am having this strange issue which i am unable to trace. When this UWP application is executed through Visual Studio it works fine, even if i run it through Start menu after installed by Visual Studio it works fine.

    The issue comes when i create a package with Visual Studio RightClick on Project -> Store -> Create App Packages -> I want to create packages for side loading.

    The package is created successfully and it installs without any error, on Executing all features works fine except for the Printing of Document. The Error which i get is as bellow.

    The code used for printing is bellow, but i don't think its an issue with the code.

      protected override void PrintTaskRequested(Windows.Graphics.Printing.PrintManager sender, Windows.Graphics.Printing.PrintTaskRequestedEventArgs e)
            {
                PrintTask printTask = null;
                printTask = e.Request.CreatePrintTask("C# Printing SDK Sample", sourceRequestedArgs =>
                {
                    PrintTaskOptionDetails printDetailedOptions = PrintTaskOptionDetails.GetFromPrintTaskOptions(printTask.Options);
    
                    // Choose the printer options to be shown.
                    // The order in which the options are appended determines the order in which they appear in the UI
                    printDetailedOptions.DisplayedOptions.Clear();
                    printDetailedOptions.DisplayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.MediaSize);
                    printDetailedOptions.DisplayedOptions.Add(Windows.Graphics.Printing.StandardPrintTaskOptions.Copies);
    
                    // Create a new list option.
                    PrintCustomItemListOptionDetails photoSize = printDetailedOptions.CreateItemListOption("photoSize", "Photo Size");
                    photoSize.AddItem("SizeFullPage", "Full Page");
                    photoSize.AddItem("Size4x6", "4 x 6 in");
                    photoSize.AddItem("Size5x7", "5 x 7 in");
                    photoSize.AddItem("Size8x10", "8 x 10 in");
    
                    // Add the custom option to the option list.
                    printDetailedOptions.DisplayedOptions.Add("photoSize");
    
                    PrintCustomItemListOptionDetails scaling = printDetailedOptions.CreateItemListOption("scaling", "Scaling");
                    scaling.AddItem("ShrinkToFit", "Shrink To Fit");
                    scaling.AddItem("Crop", "Crop");
    
                    // Add the custom option to the option list.
                    printDetailedOptions.DisplayedOptions.Add("scaling");
    
                    // Set default orientation to landscape.
                    printTask.Options.Orientation = PrintOrientation.Landscape;
    
                    // Register for print task option changed notifications.
                    printDetailedOptions.OptionChanged += PrintDetailedOptionsOptionChanged;
    
                    // Register for print task Completed notification.
                    // Print Task event handler is invoked when the print job is completed.
                    printTask.Completed += async (s, args) =>
                    {
                        await scenarioPage.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                        {
                            ClearPageCollection();
    
                            // Reset image options to default values.
                            this.photoScale = Scaling.ShrinkToFit;
                            this.photoSize = PhotoSize.SizeFullPage;
    
                            // Reset the current page description
                            currentPageDescription = null;
    
                            // Notify the user when the print operation fails.
                            if (args.Completion == PrintTaskCompletion.Failed)
                            {
                                // MainPage.Current.NotifyUser("Failed to print.", NotifyType.ErrorMessage);
                            }
                        });
                    };
    
                    // Set the document source.
                    sourceRequestedArgs.SetSource(printDocumentSource);
                });
            }
    
    
    
    
    
     protected override async void AddPrintPages(object sender, AddPagesEventArgs e)
            {
                PrintDocument printDoc = (PrintDocument)sender;
    
                // Loop over all of the preview pages
                for (int i = 0; i < NumberOfPhotos; i++)
                {
                    UIElement page = null;
                    bool pageReady = false;
    
                    lock (printSync)
                    {
                        pageReady = pageCollection.TryGetValue(i, out page);
                    }
    
                    if (!pageReady)
                    {
                        // If the page is not ready create a task that will generate its content.
                        page = await GeneratePageAsync(i + 1, currentPageDescription);
                    }
    
                    printDoc.AddPage(page);
                }
    
                // Indicate that all of the print pages have been provided.
                printDoc.AddPagesComplete();
    
                // Reset the current page description as soon as possible since the PrintTask.Completed event might fire later (long running job)
                currentPageDescription = null;
            }
    Any help resolving this issue will be appreciated.



    Please mark those posts as answer which answers your question. Faraz


    Thursday, February 7, 2019 6:31 AM

All replies

  • Hi,

    What's the OS version of your device and what's the target version of your app? Have you tried to run your app in release mode to see if there is the same exception? Does this happens every time when your try to use the print function?

    According to the screen shot, it mentions about a method in the mainpage called saveAtPrint? Does this method need to access some location that the app doesn't have permission?

    I have to say it's hard to find out where the problem occurs. It still needs more details to locate the problem. My suggestion is that you might need to use some try/catch blocks to handle some parts of the code and record which part of the code is running once the error occurs. Or you could try to use App Center , you could use the Diagnostics services of App Center that could give you a detailed error report about the exception.

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, February 7, 2019 7:43 AM
  • Hi 

    I believe i am using the latest version of OS,

    Application target is as bellow

    The function "saveAtPrint" basically calls the above code which works if the application is deployed\executed through Visual studio and it works every time, But when the application is side-loaded with the package created, it gives error every time. I tried giving every permission\Capability\Deceleration but issue still exists.

    I am going to try the APPCeneter Diagnostics as its the only thing left which i have not tried yet.


    Please mark those posts as answer which answers your question. Faraz

    Thursday, February 7, 2019 7:57 AM
  • Hi,

    Have you tried to run the app in release mode? Is there any more information about this?

    Best regards,

    Roy


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 12, 2019 5:54 AM