I'm getting this exception:
Microsoft.Maui.ApplicationModel.NotImplementedInReferenceAssemblyException: This functionality is not implemented in the portable version of this assembly. You should reference the NuGet package from your main application project in order to reference the platform-specific implementation.
at Microsoft.Maui.ApplicationModel.DataTransfer.ShareImplementation.PlatformRequestAsync(ShareFileRequest request) in /_/src/Essentials/src/Share/Share.netstandard.tvos.watchos.cs:line 11
at Microsoft.Maui.ApplicationModel.DataTransfer.ShareImplementation.RequestAsync(ShareFileRequest request) in /_/src/Essentials/src/Share/Share.shared.cs:line 129
I have followed the steps from the guide which resulted in me changing Share.RequestAsync() to Share.Default.RequestAsync(), but that didn't help.
This is my code:
string documentsPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
Directory.CreateDirectory(documentsPath); //Also added this line because of the Xamarin to MAUI upgrade
string filePath = System.IO.Path.Combine(documentsPath, "SomeRandomFile.txt");
var shareRequest = new ShareFileRequest { Title = "Share file", File = new ShareFile(filePath) };
try
{
await Share.Default.RequestAsync(shareRequest);
}
catch (Exception ex)
{
string message = ex.Message;
}
When ever I try to call the line within the try, it'll always result in the exception above. And I have no idea what package the exception is refering to... And there's only ONE project in the solution which has all the NuGet packages. I just want to share a file. I am using a device with Android 14 and it was working fine before I "up"graded from Xamarin to MAUI. And so far this is the only hurdle I haven't managed to fix myself without having resort to posting this question.
The problem seemed to be the usage of the package Microsoft.Maui.Controls.Compatilibility. Once I replaced that with the package Microsoft.Maui.Essentials (which is MAUI's equivalent of Xamarin's Xamarin.Essentials) everything was working again as expected.