调用 Windows.Storage.ApplicationData.Current.LocalFolder 时,由于对象的当前状态,操作无效

问题描述 投票:0回答:1

我有一个 Uno Platform 项目,TargetFrameworks;$(DotNetVersion)”是 ;net7.0-windows10.0.1901;net7.0; 我正在尝试使用 Windows.Storage 命名空间中的 API 来实现跨平台本地存储。代码:

public static async Task<T?> RetrieveDataAsync<T>(string filename)
{
    if (!string.IsNullOrEmpty(filename))
    {            
        try
        {
            StorageFolder localFolder = ApplicationData.Current.LocalFolder;
            StorageFile storageFile = await localFolder.GetFileAsync($"{filename}.json");
            string serializedData = await FileIO.ReadTextAsync(storageFile);
            return JsonSerializer.Deserialize<T>(serializedData);
        }
        catch (Exception ex)
        {
            string msg = ex.Message;
        }
    }
    return default(T);
}

我在“...ApplicationData.Current.LocalFolder”行上收到消息“由于对象的当前状态,操作无效”。当我尝试针对 Windows 平台进行构建时。 Uno 文档表示所有平台都支持它。这是什么原因造成的?

c# uno
1个回答
0
投票

发现问题了,这是我的一个错误,我花了很长时间才注意到。我正在调试我的应用程序的未打包版本。

© www.soinside.com 2019 - 2024. All rights reserved.