cjlotz / Xamarin.Plugins

Cross platform Xamarin Plugins
MIT License
113 stars 56 forks source link

PCL on iOS System.ArgumentNullException: Value cannot be null. Parameter name: attachment #66

Closed uwantfries closed 6 years ago

uwantfries commented 7 years ago

I am getting the following error on IOS when calling the code from PCL

System.ArgumentNullException: Value cannot be null. Parameter name: attachment

at MessageUI.MFMailComposeViewController.AddAttachmentData (Foundation.NSData attachment, System.String mimeType, System.String fileName) [0x00076] in /Users/builder/data/lanes/4691/d2270eec/source/xamarin-macios/src/build/ios/native/MessageUI/MFMailComposeViewController.g.cs:104 at Plugin.Messaging.EmailTask.SendEmail (Plugin.Messaging.IEmailMessage email) [0x00101] in :0 at XApp.MainPage.btnTestEmail_Clicked (System.Object sender, System.EventArgs e) [0x000bb] in <76d8f2c0683744789d54752507752bfd>:0 at Xamarin.Forms.Button.SendClicked () [0x00021] in <937957814f5d45be82b66795cb584841>:0 at Xamarin.Forms.Platform.iOS.ButtonRenderer.OnButtonTouchUpInside (System.Object sender, System.EventArgs eventArgs) [0x00011] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.iOS\Renderers\ButtonRenderer.cs :125

The file does exist on the file system and is readable (I can open the PDF elsewhere in my proj)

The code I am using is

var emailTask = MessagingPlugin.EmailMessenger; if (emailTask.CanSendEmail) { string path = "00000018.pdf";

            if (!path.Contains("/"))
            {
                path = DependencyService.Get<IFileHelper>().GetLocalFilePath(path);
            }

            Logging.WriteLine(Logging.LogLevel.Debug, "emailing :" + path);

            // Send a more complex email with the EmailMessageBuilder fluent interface.
            var email = new EmailMessageBuilder()
          .Subject("Emailing PDF: " + "TEST")
          .Body("Please find attached PDF document.")
          .WithAttachment(path, "application/pdf") 
          .Build();

            emailTask.SendEmail(email);
        }
prashantvc commented 7 years ago

Where does file exists on iOS? Could you print out the complete file path? I wonder if your app have any permission to access it.

madareklaw commented 7 years ago

Have you tried using "application/octet-stream" instead of "application/pdf"?

uwantfries commented 7 years ago

Thanks. I will try those suggestions.

prashantvc commented 6 years ago

I am marking this issue closed since there is no activity for 30 days. Please reopen if you continue to have any issues