question

mfeuserlast-8185 avatar image
0 Votes"
mfeuserlast-8185 asked FayWang-MSFT answered

ShareTarget results in The program *.exe: Program Trace' has exited with code 0 (0x0). The program *.exe' has exited with code -1073741819 (0xc0000005) 'Access violation'.

Hello,

I'm encountering the behavior when my App is a ShareTarget it will be killed with:

The program '[5880] Shell.exe' has exited with code -1073741819 (0xc0000005) Access violation.
The program '[5880] Shell.exe: Program Trace' has exited with code 0 (0x0).


The app does the following:

Copy the image files it received via sharetarget parameter to the apps temporary folder

Then its gonna resize the temporary image

Prompt OpenFilePicker so the user can save a copy of the temporary file stream file somewhere else

App gets closed by The program Shell.exe has exited with code -1073741819 (0xc0000005) Access violation.

If I skip step 3 (OpenFilePicker) and save the output stream into the temporary file the app behave as expected.

For me it looks like that the dialog (in this case OpenFilePicker) produces the issue here which results in an Access violation but I cant imagine how and why.

The app gets killed when calling

IStorageFile File = await FileSavePicker.PickSaveFileAsync();

When the dialog is shown, the user does nothing - wait 1-3 seconds and the app gets terminated.

PS: If I open an other dialog instead of SaveFilePicker the apps gets killed too! For example:

      MessageDialog Dialog = new MessageDialog(content);
      Dialog.Commands.Add(new UICommand(yesButton) { Id = 0 });
      Dialog.Commands.Add(new UICommand(noButton) { Id = 1 });
      return ((int)(await Dialog.ShowAsync()).Id == 0);

This occours for me on

Any idea how to fix this issue? Happens for me on Windows 1909

windows-uwp
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

FayWang-MSFT avatar image
0 Votes"
FayWang-MSFT answered

Hello,

Welcome to Microsoft Q&A!

Based on the Remarks part of FileSavePicker, it mentions

If you try to show the file picker while your app is snapped the file picker will not be shown and an exception will be thrown.

and the Remarks part of MessageDialog:

In : Your app can call showAsync from within the activated handler (the onactivated event or the CoreApplicationView.Activated event ), and paint operations then occur behind the app's splash screen.

So it is not suitable to use FileSavePicker and MessageDialog in the OnShareTargetActivated, it's better to use them in the MainPage. You could navigate to the Main page and activate the current window. After that, passing the parameter to the Main page and in the Loaded event using them. For example:

App.xaml.cs:

 protected override void OnShareTargetActivated(ShareTargetActivatedEventArgs args)
 {
     ShareOperation shareOperation = args.ShareOperation;
     if (shareOperation.Data.Contains(StandardDataFormats.StorageItems))
     {
         Frame rootFrame = Window.Current.Content as Frame;
         if (rootFrame == null)
         {
             rootFrame = new Frame();
             Window.Current.Content = rootFrame;
         }
         if (rootFrame.Content == null)
         {
             rootFrame.Navigate(typeof(MainPage), shareOperation.Data);
         }
         // Ensure the current window is active
         Window.Current.Activate();
     }
 }

MainPage.cs:

 private async void MainPage_Loaded(object sender, RoutedEventArgs e)
 {
     var savePicker = new Windows.Storage.Pickers.FileSavePicker();
     ......
     Windows.Storage.StorageFile file = await savePicker.PickSaveFileAsync();
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.