Windows通用应用程序错误System.IO.FileSystem - 科尔多瓦
我想在Windows 10 cordova应用程序中使用两个不同的窗口UWP项目。两个项目都会产生相同的错误。在其中一个项目的代码如下:Windows通用应用程序错误System.IO.FileSystem - 科尔多瓦
using System;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Json;
using System.Threading.Tasks;
using Windows.Foundation;
using Windows.Storage;
namespace DiskSpaceLibrary
{
public sealed class DiskSpace
{
internal static readonly StorageFolder[] APP_FOLDERS = {
ApplicationData.Current.LocalFolder,
ApplicationData.Current.RoamingFolder,
ApplicationData.Current.TemporaryFolder
};
[DataContract]
internal class Result
{
[DataMember]
internal ulong app = 0;
[DataMember]
internal ulong total = 0;
[DataMember]
internal ulong free = 0;
}
// Manually compute total size of the given StorageFolder
private static ulong sizeFolder(StorageFolder folder)
{
ulong folderSize = 0;
try
{
DirectoryInfo dirInfo = new DirectoryInfo(folder.Path);
// Get back a prefilled (with size) list of files contained in given folder
foreach (var fileInfo in dirInfo.EnumerateFiles("*", SearchOption.AllDirectories))
{
folderSize += (ulong)fileInfo.Length;
}
}
catch (Exception e)
{
System.Diagnostics.Debug.WriteLine(e.ToString());
return 0;
}
return folderSize;
}
// Return the system FreeSpace and Capacity properties
private async static Task<IDictionary<string, object>> getExtraProperties()
{
var basicProperties = await Windows.Storage.ApplicationData.Current.LocalFolder.GetBasicPropertiesAsync();
return await basicProperties.RetrievePropertiesAsync(new string[] { "System.FreeSpace", "System.Capacity" });
}
// Class Entry point
public static IAsyncOperation<string> info(string args)
{
// Entry point in WinRT can not return Task<T> - so here is a trick to convert IAsyncOperation (WinRT) into classic C# async
return infoTask().AsAsyncOperation();
}
// The real disk space work is done here within some asynchronous stuff
private async static Task<string> infoTask()
{
Result result = new Result();
// Run folder discovery into another Thread to not block UI Thread
await Task.Run(() => {
foreach (var folder in APP_FOLDERS)
{
result.app += sizeFolder(folder);
}
});
await getExtraProperties().ContinueWith(propertiesTask =>
{
result.free = (ulong)propertiesTask.Result["System.FreeSpace"];
result.total = (ulong)propertiesTask.Result["System.Capacity"];
});
// Return JSON Result
DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Result));
MemoryStream outputMs = new MemoryStream();
serializer.WriteObject(outputMs, result);
outputMs.Position = 0;
StreamReader sr = new StreamReader(outputMs);
return sr.ReadToEnd();
}
}
}
这个项目是从https://github.com/sqli/sqli-cordova-disk-space-plugin
它只是查找使用的磁盘空间并报告使用System.IO.DirectoryInfo和使用,可用空间异步方法来获得可用空间和容量。
当我建立这是它生成winmd文件没有问题,我已经正确地注册并加载这些在我的科尔多瓦(Visual Studio 2017)项目,建立为Windows 10并运行 - 当我在主cordova项目
DiskSpacePlugin.info({}, function (ok) { console.log(ok); }, function (err) { console.log(err); });
我得到这样的结果在控制台
WinRTError: The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at DiskSpaceLibrary.DiskSpace.sizeFolder(StorageFolder folder)
at DiskSpaceLibrary.DiskSpace.<>c__DisplayClass5_0.<infoTask>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.Ex
console-via-logger.js (173,15)
{
[functions]: ,
__proto__: { },
asyncOpCausalityId: 461,
asyncOpSource: { },
asyncOpType: "Windows.Foundation.IAsyncOperation`1<String>",
description: "The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at DiskSpaceLibrary.DiskSpace.sizeFolder(StorageFolder folder)
at DiskSpaceLibrary.DiskSpace.<>c__DisplayClass5_0.<infoTask>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.Ex",
message: "The system cannot find the file specified.
System.IO.FileNotFoundException: Could not load file or assembly 'System.IO.FileSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.
at DiskSpaceLibrary.DiskSpace.sizeFolder(StorageFolder folder)
at DiskSpaceLibrary.DiskSpace.<>c__DisplayClass5_0.<infoTask>b__0()
at System.Threading.Tasks.Task.Execute()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.Ex",
name: "WinRTError",
number: -2147024894
}
我也曾尝试另一个模块在科尔多瓦窗口10项目解压文件(我没有这一个源然而说到从https://github.com/Culture22/cordova-windows10-zip)它来了当我尝试在应用程序中运行它时,会出现完全相同的错误消息。
我已经搜索了并且在过去的4天里查找了这个问题,并且我无法进展,所使用的方法都是由框架明显看着的支持(msdn.microsoft.com/en-us/library/ windows/apps/mt185496.aspx) - 有没有人有任何见解?
看起来像你引用的库引用了System.IO.FileSystem.dll,但是无论出于何种原因,它没有被部署到应用程序中。我建议尝试添加到您的应用程序的System.IO.FileSystem.dll nuget引用。
我相信科尔多瓦7创造Windows 10 UWP应用程序在一个叫做远程模式的东西 - 它似乎不支持包括额外的库。仍然在做这件事,但能够编译和运行上述后,我删除了外部库,并使用UWP可怜的库,而不是像Windows.Data.Json序列化,并通过文件夹使用DIrectoryInfo,而不是使用Windows取出循环。 Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync(); - 我无法解决如何解决这个问题。 –
我刚刚在另一个问题上发现了此评论:Cordova UWP应用程序只能使用NetCore,而不能使用完整的.Net Framework,无论它们是直接的.Net应用程序还是在WRC内部调用.Net –
System.IO.FileSystem不是框架的一部分其nuget包https://www.nuget.org/packages/System.IO.FileSystem/ – Mick
是的,我明白,甚至已经加载到项目中但它甚至不应该根据MS文档使用它? –