Essentials: UnauthorizedAccessException: Access to the path is denied [Bug]

Created on 19 Nov 2019  路  4Comments  路  Source: xamarin/Essentials

using code from the essential example. Works fine on iOS and most Android versions. But I have one Oppo Android phone on 6.0 that throws an exception when trying to share my local pdf. As you can see in my code snippet, I am copying my local file to the cache directory for other apps to access it. Any ideas?

`

        try
        {
            var message = new EmailMessage
            {
                Subject = subject,
                Body = body,
                To = recipients
            };

           var fn = "Attachment.txt";
           var file = Path.Combine(FileSystem.CacheDirectory, fn);
           File.WriteAllText(file, "Hello World");

            message.Attachments.Add(new EmailAttachment(file));
            await Email.ComposeAsync(message);
            successful = true;
        }
        catch (FeatureNotSupportedException fbsEx)
        {
            // Email is not supported on this device
        }
        catch (Exception ex)
        {
            // Some other exception occurred
        }

`

bug invalid

All 4 comments

I don't get an exception when copying the file. I get the exception when calling ComposeAsync()

I upgraded my visual studio to the preview version and it DID fix the problem. Wow, I would never look there. Thanks @acaliaro for your tip!

Closing as it seems fixed there.

Was this page helpful?
0 / 5 - 0 ratings