当我尝试使用 Xamarin.Essentials 的 FilePicker 类时,我的应用程序关闭而没有引发任何异常。
我做了什么:
添加:
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
和代码:
async Task<FileResult> PickAndShow(PickOptions options)
{
try
{
var result = await FilePicker.PickAsync();
if (result != null)
{
Text = $"File Name: {result.FileName}";
if (result.FileName.EndsWith("jpg", StringComparison.OrdinalIgnoreCase) ||
result.FileName.EndsWith("png", StringComparison.OrdinalIgnoreCase))
{
var stream = await result.OpenReadAsync();
Image = ImageSource.FromStream(() => stream);
}
}
}
catch (Exception ex)
{
// The user canceled or something went wrong
}
}
我正在为 MacOS 使用 VS。
关闭应用的视频: https ://drive.google.com/file/d/1H1488amryi_p7mkg7JdmhcGAE569KON4/view?usp=sharing
请帮我看看我错过了什么?
编辑:
发生错误的行
var result = await FilePicker.PickAsync();
例外:
不抛出异常;
应用退出:
[Mono] 请求加载 Xamarin.Essentials.dll 的引用 5(共 8 个) [Mono] 加载 Xamarin.Essentials.dll asmctx DEFAULT 的引用 5,寻找 System.Core,Version=2.0.5.0,Culture=neutral,PublicKeyToken= 7cec85d7bea7798e [Mono] Assembly Ref addref Xamarin.Essentials[0x7ddc93de80] -> System.Core[0x7d850f7880]: 10 [Choreographer] 跳过 711 帧!应用程序可能在其主线程上做了太多工作。[OpenGLRenderer] 戴维!持续时间=12935ms;Flags=0, IntendedVsync=24578200518089, Vsync=24591127790687, OldestInputEvent=9223372036854775807, NewestInputEvent=0, HandleInputStart=24591131789208, AnimationStart=24591131799939, PerformTraversalsStart=24591132369131, DrawStart=24591132532323, SyncQueued=24591132572054, SyncStart=24591133134246, IssueDrawCommandsStart=24591133217554, SwapBuffers= 24591134886554,
设备日志: