繁体   English   中英

Xamarin Forms 和 xam.plugin.media:无法解析对 Xamarin.Essentials.Permissions 的引用

[英]Xamarin Forms and xam.plugin.media: could not resolve reference to Xamarin.Essentials.Permissions

我正在关注如何使用 Xamarin Forms 在手机上浏览图像的教程。 在 MainPage.xaml 我有:

        <Button Text="Select a picture"
                Clicked="SelectImageButton_Clicked"/>
        <Image x:Name="selectedImage"/>
    </StackLayout>

在 MainPage.xaml.cs 中,是 Click 事件处理程序的以下代码:

private async void SelectImageButton_Clicked(object sender, EventArgs e)
        {
            await CrossMedia.Current.Initialize();
            if (!CrossMedia.Current.IsPickPhotoSupported)
            {
                await DisplayAlert("Error", "This is not supported on your device", "OK");
                return;
            }

            var mediaOptions = new PickMediaOptions()
            {
                PhotoSize = PhotoSize.Medium
            };

            var selectedImageFile = await CrossMedia.Current.PickPhotoAsync(mediaOptions);

            if (selectedImageFile == null)
            {
                await DisplayAlert("Error", "The picture is null", "OK");
                return;
            }
                selectedImage.Source = ImageSource.FromStream(() => selectedImageFile.GetStream());

        }

构建解决方案有效,但只要我按下模拟器中的按钮,就会出现错误。 因此,我已将 linker( Droid Properties > Android Options > Linking )设置为仅 Sdk 程序集。

然后在尝试构建解决方案时出现以下错误:

Java.Interop.Tools.Diagnostics.XamarinAndroidException: error XA2006: Could not resolve reference to 'Xamarin.Essentials.Permissions/BasePlatformPermission' (defined in assembly 'Plugin.Media, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null') with scope 'Xamarin.Essentials, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'. When the scope is different from the defining assembly, it usually means that the type is forwarded.

I have created a new project, updated the Xamarin.Forms NuGet Package to version 4.6.0.726, updated the Xamarin.Essentials version to 1.5.3.1 and then installed the xam.plugin.media package, version 5.0.1

在尝试查找解决方案的类似问题时,我发现可能对 Essentials 的引用未指向正确的版本,我应该在解决方案的 Android 项目中更改它。 但是,由于我对 Xamarin 和 Android 开发非常陌生,我不知道在哪里可以找到这些参考资料。 我是否在寻求解决方案的正确轨道上,如果是:我需要采取哪些步骤来解决这个问题?

If (!rightTrack)
{
return solution;
}

非常感谢您的意见!

当我使用相同版本的 Xamarin.Forms、Xamarin.Essentials、xam.plugin.media 测试您的代码时,我重现了错误。

您可以使用 xam.plugin.media 的旧版本 4.0.1.5。 该错误将修复。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM