我正在为我的应用程序使用本地存储的Json文件。使用Visual Studio的模拟器读取和写入文件可以正常工作。当我连接设备并尝试在该设备上运行时,我无法访问我的Json文件。无法访问Windows 8.1手机设备上的文件
我的json文件被设置为内容和始终复制。
这是我的阅读文件的try语句。我试过两种主要的方法来访问文件Current.InstalledLocation
和Uri("ms-appx:///)
。两者都似乎在模拟器中工作,但都不能在设备上工作。
try
{
var package = Windows.ApplicationModel.Package.Current.InstalledLocation;
StorageFolder folder = await package.GetFolderAsync("Data");
StorageFile file = await folder.GetFileAsync("Users.json");
//Uri dataUri = new Uri("ms-appx:///Data/Users.json");
//StorageFile file = await StorageFile.GetFileFromApplicationUriAsync(dataUri);
string jsonText = await FileIO.ReadTextAsync(file);
JsonArray jsonArray = JsonArray.Parse(jsonText);
foreach (JsonValue userValue in jsonArray)
{
//Build my model object out of json
}
}
catch(Exception e)
{
//Creating instance for the MessageDialog Class
//and passing the message in it's Constructor
MessageDialog msgbox = new MessageDialog(e.Message);
//Calling the Show method of MessageDialog class
//which will show the MessageBox
await msgbox.ShowAsync();
}
输出窗口显示:
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
Exception thrown: 'System.ArgumentException' in mscorlib.ni.dll
编辑: 的尝试捕捉回路不捕相关文件系统访问问题的异常。
在启动步进时通过我在StorageFile file = await folder.GetFileAsync("Users.json");
失败了,为什么我通过一个按钮,我在string jsonText = await FileIO.ReadTextAsync(file);
设备故障我期待上运行我的应用程序触发的功能是运行Windows Embedded 8.1手持更新2(其ToughPad Panazonic FZ-E1)。我是否需要定位Windows 8.1而不是Windows Phone 8.1?它一直在使用手机正常工作,直到控制POS条形码扫描仪。
任何帮助,将不胜感激我很茫然。我的问题是否可能是由设备上的设置引起的?
而不仅仅是信息,您可以分享全'的ToString()异常的'输出,包括异常类型,消息和追踪? – dbc
经过检查我的try catch块甚至没有捕捉异常。我所看到的例外情况不知从何而来。 mscorlib异常似乎没有引起任何问题,除了踢我离开我的断点一步。 – JaredStroeb