我正在使用Xamarin和MVVMCross实现一个Android应用程序。在我的PCL我有一个ZipUtility类和下面的方法:无效的il代码System.IO.Compression.ZipFile.OpenRead()方法正文为空
public NoDataResponse UnCompressZipFile(string path, string filename)
{
NoDataResponse response = new NoDataResponse();
StringBuilder sb = new StringBuilder();
sb.AppendLine(string.Format("\r\nUnzipping '{0}' in '{1}' folder...", filename, path));
try
{
using (ZipArchive archive = ZipFile.Open(filename, ZipArchiveMode.Read))
{
foreach (System.IO.Compression.ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".txt", StringComparison.OrdinalIgnoreCase))
{
System.IO.Compression.ZipFile.ExtractToDirectory(filename, path);
break;
}
}
}
response.IsCallSuccessful = true;
sb.AppendLine(string.Format("\r\nFinished Unzipping file {0}.\r\n", filename));
response.BusinessEntityMessage = sb.ToString();
}
catch (Exception ex)
{
response.IsCallSuccessful = false;
response.BusinessEntityMessage = "\r\nUNZIPPING ERROR: " + ex.Message + "\r\n";
}
return response;
}
zip文件类我的方法里面是System.IO.Compression(System.IO.Compression.FileSystem命名空间)的一部分。
当我执行我得到以下错误的方法:
System.InvalidProgramException:无效IL代码在System.IO.Compression.ZipFile:打开(字符串,System.IO.Compression.ZipArchiveMode):方法体是空的。 at HHT.Core.Globals.ZipUtility.UnCompressZipFile(System.String path,System.String filename)[0x00033] in c:\ Sandbox \ HHT-ANDROID \ HHTApp \ HHT.Core \ Globals \ ZipUtility.cs:32
我不确定缺少什么,因为相同的代码在PCL之前完美工作。
我也尝试从我的DROIDUI项目中使用依赖注入(N = 31 slodge)运行相同的类,但仍然得到相同的错误。
我希望对此有任何意见或想法。
非常感谢您的意见。其实你解决了我的问题。正如你所猜测的那样,我正在提供一个参考汇编。只要我从C:\ Windows \ Microsoft.Net \ Framework中引用了System.IO.Compression,它就起作用了。再次感谢您。 – Spyros
不客气。这听起来不像是正确的修复,但你不应该直接添加对平台实现的引用,因为这可能会破坏其他场景。然而,如果这能解决你的问题,而不是Xamarin方面的错误。更好的临时解决方法是继续使用PCL中的NuGet包,并确保您的应用程序不部署System.IO.Compression.dll。 –
我昨天已经更新到最新的Xamarin Android版本和我的ZipArchive类了我System.NotImplementedException:请求的功能未实现。我不知道我以前使用的Xamarin Android版本是否因为允许类完全正常工作而产生了一个错误。当你说继续使用Nuget包时,你的意思是Microsoft.Bcl.Compression是否正确?说实话,我还没有使用过那个,但正如你所说,你只发布Windows Phone的实现,所以它甚至不会允许我从Nuget安装它。 – Spyros