'IAsyncOperation<>'Xamarin 表单 [英] 'IAsyncOperation<>' Xamarin Forms

查看:70
本文介绍了'IAsyncOperation<>'Xamarin 表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

When using the exact same code in a UWP App an Xamarin Forms app, I get the following error on the Xamarin.Forms program but not on the UWP program.

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

Error CS0012 The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly '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();
    }

推荐答案

'IAsyncOperation<>' Xamarin 表单

'IAsyncOperation<>' Xamarin Forms

问题是您错过了 System.Runtime.WindowsRuntime 程序集,您可以手动添加它.右键单击 Dependencies Add reference-> Browse -> 从这个路径找到它 (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll).

The problem is that you have missed System.Runtime.WindowsRuntime assembly, you could add it manually. right click the Dependencies Add reference-> Browse -> find it from this path (C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll).

更新

该程序集应该自动添加到 Xamarin Forms 应用程序中,对吗?我的意思是我以前从未需要手动添加它.

That assembly should be added automatically to a Xamarin Forms app, correct? I mean I have never had to add it manually before.

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

Sure, but in early version, we need add the reference manually. And I checked your thread again, I found you used StorageFile in forms app class. However, StorageFile is specific class for uwp platform please avoid use it in forms, if you want to file access, you could dependency service to access file for each platform.

这篇关于'IAsyncOperation&lt;&gt;'Xamarin 表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆