Andrea485
Andrea485

Reputation: 537

App crash on share file dialog only in release mode

My application crash when I open the file share dialog, happens only in release mode, in debug mode everything works correctly. this is my code:

        private List<IStorageFile> fileSelectedToShare;

        private void shareFileAppBarButton_Click(object sender, RoutedEventArgs e)
            {
                dataTransferManager = DataTransferManager.GetForCurrentView();
                dataTransferManager.DataRequested += DataTransferManager_DataRequested;

                DataTransferManager.ShowShareUI();
            }

            private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
            {
                if (fileSelectedToShare == null) return;

                DataRequest request = args.Request;
                if (fileSelectedToShare.Count != 0) { 
                    request.Data.Properties.Title = "Share";
                    request.Data.Properties.Description = "Share the selected document";
                    request.Data.SetStorageItems(fileSelectedToShare);
                    fileSelectedToShare.Clear();
                }
                dataTransferManager.DataRequested -= DataTransferManager_DataRequested;
            }

fileSelectedToShare is initialized and contains files.

this is the exception:

System.Runtime.InteropServices.MissingInteropDataException: 'ComTypeMarshalling_MissingInteropData, System.Collections.Generic.IEnumerable. For more information, visit http://go.microsoft.com/fwlink/?LinkId=623485'

Upvotes: 1

Views: 248

Answers (1)

A. Milto
A. Milto

Reputation: 2383

Not sure why, but copying the file references into another collection and passing the latter into request.Data.SetStorageItems() makes your code work:

    private void DataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs args)
    {
        if (fileSelectedToShare == null) return;

        DataRequest request = args.Request;
        if (fileSelectedToShare.Count != 0)
        {
            request.Data.Properties.Title = "Share";
            request.Data.Properties.Description = "Share the selected document";

            List<IStorageItem> files = new List<IStorageItem>(fileSelectedToShare);
            request.Data.SetStorageItems(files);

            fileSelectedToShare.Clear();
        }
        dataTransferManager.DataRequested -= DataTransferManager_DataRequested;
    }

Upvotes: 1

Related Questions