尝试使用来自 PCL 项目的 PCL 存储读取文件时出现异常

Exception while trying to read file usin PCLStorage from PCL project

我正在尝试使用 PCLStoragePCL 项目获取文件,如下所示。我在 Visual Studio 2015 Professional 中使用 Xamarin。

IFile file = await FileSystem.Current.GetFileFromPathAsync("file\path");

但我遇到异常:

System.NotImplementedException: This functionality is not implemented in the portable version of this assembly. You should reference the PCLStorage NuGet package from your main application project in order to reference the platform-specific implementation.

您需要将 PCLStorage NuGet 添加到您的 PCL 和特定于平台的项目中。

所以如果你有以下解决方案:

PCL
Android
iOS

您需要将其添加到所有这些:

PCL
    PCLStorage
Android
    PCLStorage
iOS
    PCLStorage

为什么?因为 NuGet 使用诱饵和开关技术,其中 PCL 包含带有诱饵的简单外观。在运行时,这会被特定于平台的实现切换。