无效的il代码System.IO.Compression.ZipFile.OpenRead()方法体为空

我正在使用Xamarin和MVVMCross实现一个Android应用程序。 在我的PCL中,我有一个ZipUtility类和以下方法:

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; } 

我的方法中的ZipFile类是System.IO.Compression(System.IO.Compression.FileSystem命名空间)的一部分。

当我执行该方法时,我收到以下错误:

System.InvalidProgramException:System.IO.Compression.ZipFile中的IL代码无效:Open(string,System.IO.Compression.ZipArchiveMode):方法体为空。 at HHT.Core.Globals.ZipUtility.UnCompressZipFile(System.String path,System.String filename)[0x00033]在c:\ Sandbox \ HHT-ANDROID \ HHTApp \ HHT.Core \ Globals \ ZipUtility.cs:32

我不确定缺少什么,因为相同的代码在PCL内部之前完美运行。

我也尝试使用dependency injection(N = 31 slodge)从我的DROIDUI项目运行相同的类,但仍然得到相同的错误。

我将不胜感激任何评论或想法。

听起来您正在为Android设备部署引用程序集(引用程序集仅用于编译,因此不包含IL)。

您使用的是哪个版本的System.IO.Compression ? 我假设您正在使用Microsoft.Bcl.Compression NuGet包?

我们的NuGet包不提供Android的实现。 事实上,我们只为Windows Phone提供了一个实现 – 对于所有其他平台,我们使用平台附带的平台。

我不确定Xamarin是否支持System.IO.Compression.dll(包括ZipArchive)。 之前可能有用的原因是因为您在安装NuGet软件包后重新定位了PCL。

根据您到目前为止的调查结果,我打赌您可以通过将Mac安装程序中的Xamarin.Android System.IO.Compression.dll复制到以下内容来修复错误:

C:\ Program Files(x86)\ Reference Assemblies \ Microsoft \ Framework \ MonoAndroid \ v1.0 \

目前(意外)Xamarin.Android Windows安装程序中缺少此程序集。 已经提交了一个关于此问题的错误,因此默认情况下,程序集应该存在于将来的版本中。

如果这不起作用,请务必报告该结果,以便我们进一步调查!