【问题标题】:'IAsyncOperation<>' Xamarin Forms'IAsyncOperation<>' Xamarin 表单
【发布时间】:2020-10-04 09:56:42
【问题描述】:

在 UWP 应用和 Xamarin Forms 应用中使用完全相同的代码时,我在 Xamarin.Forms 程序上收到以下错误,但在 UWP 程序上却没有。

错误 CS0012 类型“IAsyncOperation”在未引用的程序集中定义。您必须添加对程序集“Windows.Foundation.FoundationContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime”的引用。

这是我的代码。

 public App()
    {
        this.InitializeComponent();
        this.Suspending += OnSuspending;

        Task task = CopyAssetsDatabase();
    }

    private async Task CopyAssetsDatabase()
    {

        StorageFile file;

        var root = Windows.Storage.ApplicationData.Current.LocalFolder.Path;
        var dbPath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "ExpressEMR.db");

        try
        {
            file = await Windows.Storage.ApplicationData.Current.LocalFolder.GetFileAsync("ExpressEMR.db");
        }
        catch
        {
            StorageFile Importedfile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/ExpressEMR.db"));
            file = await Importedfile.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder);
        }
        throw new NotImplementedException();
    }

【问题讨论】:

    标签: windows xamarin.forms uwp sdk


    【解决方案1】:

    'IAsyncOperation' Xamarin 表单

    问题是您错过了System.Runtime.WindowsRuntime 程序集,您可以手动添加它。右击Dependencies添加引用->浏览->从此路径(C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll)找到它。

    更新

    该程序集应该自动添加到 Xamarin Forms 应用程序中,对吗?我的意思是我以前从来没有手动添加它。

    当然可以,但在早期版本中,我们需要手动添加引用。我再次检查了您的帖子,发现您在表单应用程序类中使用了StorageFile。但是,StorageFile是uwp平台的特定类,请避免在表单中使用它,如果你想文件访问,你可以dependency service访问每个平台的文件。

    【讨论】:

    • Nico,该程序集应该自动添加到 Xamarin Forms 应用程序中,对吗?我的意思是我以前从未手动添加它。
    猜你喜欢
    • 1970-01-01
    • 2019-03-20
    • 2018-01-02
    • 2020-04-28
    • 2021-01-31
    • 2018-03-11
    • 2020-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多