无效的il代码System.IO.Compression.ZipFile.OpenRead()方法主体为空 [英] Invalid il code System.IO.Compression.ZipFile.OpenRead() Method body is empty

查看:224
本文介绍了无效的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:Open(字符串,System.IO.Compression.ZipArchiveMode)中的无效IL代码:方法主体为空. 在c:\ Sandbox \ HHT-ANDROID \ HHTApp \ HHT.Core \ Globals \ ZipUtility.cs:32

我不确定缺少什么,因为相同的代码在进入PCL之前可以正常工作.

我也尝试过使用DROIDUI项目中的依赖项注入(N = 31 slodge)运行相同的类,但仍然出现相同的错误.

我对此表示任何意见或想法,我们将不胜感激.

解决方案

听起来您正在将参考程序集部署到Android设备(参考程序集仅用于编译,因此不包含IL).

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

我们的NuGet软件包不提供Android的实现.实际上,我们仅提供Windows Phone的一种实现-对于所有其他平台,我们使用该平台附带的实现.

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

I 'am implementing an android app using Xamarin and MVVMCross. Inside my PCL I have a ZipUtility class and the following method:

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

The ZipFile Class inside my method is part of the System.IO.Compression (System.IO.Compression.FileSystem namespace).

When I execute the method I get the following error:

System.InvalidProgramException: Invalid IL code in System.IO.Compression.ZipFile:Open (string,System.IO.Compression.ZipArchiveMode): method body is empty. 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

I'm not sure what is missing because the same code was working perfectly before inside the PCL.

I have also tried to run the same class using dependency injection (N=31 slodge) from my DROIDUI project and still get the same error.

I would appreciate any comments or ideas on this.

解决方案

It sounds like you're deploying a reference assembly to your Android device (a reference assembly is only for the compilation and thus doesn't contain IL).

Which version of System.IO.Compression are you using? I assume you're using the Microsoft.Bcl.Compression NuGet package?

Our NuGet package doesn't provide an implementation for Android. In fact we only ship an implementation for Windows Phone -- for all other platforms we use the one that ships with the platform.

I'm not sure whether Xamarin supports the System.IO.Compression.dll (which includes ZipArchive). The reason it may have worked previously is because you retargeted the PCL after installing the NuGet package.

这篇关于无效的il代码System.IO.Compression.ZipFile.OpenRead()方法主体为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆