最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Share.Default.RequestAsync() throwing not implemented exception after upgrading from Xamarin to MAUI? - Stack Overflow

programmeradmin0浏览0评论

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/Sharestandard.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.

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.

Share Improve this question asked Feb 7 at 4:19 Mateusz HaexMateusz Haex 11 bronze badge New contributor Mateusz Haex is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct. 10
  • It is a bit curious why you have to call CreateDirectory? That implies that the directory, and, therefore the file doesn't exist. How do you share a non-existant file? Be sure that the file exists before attempting to share it. – Stephen Quan Commented Feb 7 at 6:58
  • @StephenQuan, the file exists. That is certainly not the problem. That line is just a quirk of MAUI as noted in the code. – Mateusz Haex Commented Feb 7 at 8:18
  • @MateuszHaex What platform are you trying this on? – Bhavanesh N Commented Feb 7 at 9:32
  • @BhavaneshN, what do you mean with Platform? If you mean the API level, I'm using API 34 for Android 14. – Mateusz Haex Commented Feb 7 at 10:37
  • Have you tried other locations? I've had great success with FileSystem.Current.AppDataDirectory – Stephen Quan Commented Feb 7 at 10:37
 |  Show 5 more comments

1 Answer 1

Reset to default 0

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.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论