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

编程入门 行业动态 更新时间:2024-10-19 21:20:26
本文介绍了无效的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()方法主体为空

本文发布于:2023-11-09 20:45:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1573396.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:为空   主体   代码   方法   System

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!