locked
Unauthorized exception!

    Question

  • I am getting this error 

    An exception of type 'System.UnauthorizedAccessException' occurred in Resolve.exe but was not handled in user code
    Additional information: Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED))

    But there are two codes the messagebox one dosent work the other one does. The first is the one which dosent work the second one works!

    private async void yesBtnClick(IUICommand command)
            {
               
                FileOpenPicker imagePicker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.Thumbnail,
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                    FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
                };
                StorageFile pickedImage = await imagePicker.PickSingleFileAsync();
    
                {
                    this.imageFile = pickedImage;
                    // Display the image in the UI.
                    IRandomAccessStream displayStream = await pickedImage.OpenAsync(FileAccessMode.Read);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(displayStream);
                    CapturedPhoto.Source = bitmapImage;
                }
            }

    private async void importa_Click(object sender, RoutedEventArgs e)
            {
                FileOpenPicker imagePicker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.Thumbnail,
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                    FileTypeFilter = { ".jpg", ".png", ".bmp", ".gif", ".tif" }
                };
                StorageFile pickedImage = await imagePicker.PickSingleFileAsync();
                
                {
                    this.imageFile = pickedImage;
                    // Display the image in the UI.
                    IRandomAccessStream displayStream = await pickedImage.OpenAsync(FileAccessMode.Read);
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(displayStream);
                    CapturedPhoto.Source = bitmapImage;
                }
            }
    


    pratik

    Wednesday, April 23, 2014 5:51 AM

Answers

  • You can't open it directly from the MessageDialog command. The MessageDialog is still active at that point. You'll have to delay bringing up the FilePicker until after the dialog has closed.

    That said, opening multiple modal dialogs in sequence should generally be avoided. If you can redesign the workflow to remove the MessageDialog and handle that query inline your users will likely be much happier.

    --Rob

    Wednesday, April 23, 2014 7:42 AM
    Owner
  • The right thing would be to redesign the app so you don't push out sequential MessageDialogs. Your users will thank you for this.

    Beyond that, how best to delay it will depend on your app. I can't give you a generic solution that I'd recommend.

    --Rob

    Monday, April 28, 2014 11:53 PM
    Owner

All replies

  • The code in those looks identical, so if one works and the other doesn't it's probably the context.

    Where exactly does this fail? When you call PickSingleFileAsync?

    Where does this get called? Is it in the handler for a MessageDialog's command? If so then that is expected. The app can have only one such window open at a time. You'll need to defer the file picker until after that command has finished and the MessageDialog has completed.

    --Rob

    Wednesday, April 23, 2014 6:40 AM
    Owner
  • Yes, It does show the error in the line of code. This is a completely different button. So it is getting called once only. Yes this a button in the messagebox if the person clicks ok then he should be redirected to the import how do I do that?

      StorageFile pickedImage = await imagePicker.PickSingleFileAsync();



    pratik

    Wednesday, April 23, 2014 7:21 AM
  • You can't open it directly from the MessageDialog command. The MessageDialog is still active at that point. You'll have to delay bringing up the FilePicker until after the dialog has closed.

    That said, opening multiple modal dialogs in sequence should generally be avoided. If you can redesign the workflow to remove the MessageDialog and handle that query inline your users will likely be much happier.

    --Rob

    Wednesday, April 23, 2014 7:42 AM
    Owner
  • How can I delay it?

    pratik

    Wednesday, April 23, 2014 9:03 AM
  • The right thing would be to redesign the app so you don't push out sequential MessageDialogs. Your users will thank you for this.

    Beyond that, how best to delay it will depend on your app. I can't give you a generic solution that I'd recommend.

    --Rob

    Monday, April 28, 2014 11:53 PM
    Owner