2017-08-03 102 views
0

我想在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) - 有沒有人有任何見解?

+0

System.IO.FileSystem不是框架的一部分其nuget包https://www.nuget.org/packages/System.IO.FileSystem/ – Mick

+0

是的,我明白,甚至已經加載到項目中但它甚至不應該根據MS文檔使用它? –

回答

0

看起來像你引用的庫引用了System.IO.FileSystem.dll,但是無論出於何種原因,它沒有被部署到應用程序中。我建議嘗試添加到您的應用程序的System.IO.FileSystem.dll nuget引用。

+0

我相信科爾多瓦7創造Windows 10 UWP應用程序在一個叫做遠程模式的東西 - 它似乎不支持包括額外的庫。仍然在做這件事,但能夠編譯和運行上述後,我刪除了外部庫,並使用UWP可憐的庫,而不是像Windows.Data.Json序列化,並通過文件夾使用DIrectoryInfo,而不是使用Windows取出循環。 Storage.FileProperties.BasicProperties basicProperties = await file.GetBasicPropertiesAsync(); - 我無法解決如何解決這個問題。 –

+0

我剛剛在另一個問題上發現了此評論:Cordova UWP應用程序只能使用NetCore,而不能使用完整的.Net Framework,無論它們是直接的.Net應用程序還是在WRC內部調用.Net –

相關問題