在 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();
}
'IAsyncOperation' Xamarin 表单
问题是你错过了System.Runtime.WindowsRuntime
程序集,您可以手动添加它。右键单击Dependencies
添加引用->浏览->从此路径找到它(C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll
).
Update
该程序集应该自动添加到 Xamarin Forms 应用程序中,对吗?我的意思是我以前从未需要手动添加它。
当然可以,但是在早期版本中,我们需要手动添加引用。我又检查了你的帖子,发现你用过StorageFile
在表单应用程序类中。但是,StorageFile是uwp平台的特定类,请避免在表单中使用它,如果您想要文件访问,您可以依赖服务 https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction访问每个平台的文件。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)