Unity 打包IL2cpp 出现Win32Exception

本文介绍了一种常见问题:在使用Unity进行打包时,由于杀毒软件如360安全卫士误将il2cpp.exe程序隔离而导致出现Win32Exception等错误。文中分享了解决这一问题的具体步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

请检查本地杀毒软件的隔离目录是否将相关的.exe 程序隔离。

我在打包的时候遇到Win32Exception: ApplicationName=‘“D:\XXX\Unity\Editor\Data\MonoBleedingEdge\bin\mono.exe。

failed running il2cpp.exe等错误。

进入360安全卫士之后才发现我的il2cpp.exe 被隔离了。....

### 实现 Unity IL2CPP 构建中的 Excel 文件读写 为了在 Unity 使用 IL2CPP 构建时实现 Excel 文件的读写功能,可以采用以下几种方法: #### 方法一:使用第三方库 NPOI 或 EPPlus NPOI 和 EPPlus 是两个广泛使用的 .NET 库,用于处理 Excel 文件。 对于 **NPOI**: ```csharp using System.IO; using NPOI.SS.UserModel; public class ExcelHandler { public void WriteToExcel(string filePath) { IWorkbook workbook = new HSSFWorkbook(); ISheet sheet = workbook.CreateSheet("Test Sheet"); // 创建一行并设置单元格值 IRow row = sheet.CreateRow(0); row.CreateCell(0).SetCellValue("Hello"); row.CreateCell(1).SetCellValue("World"); using (FileStream fs = File.Create(filePath)) { workbook.Write(fs); } } public string ReadFromExcel(string filePath) { using (FileStream file = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { IWorkbook workbook = WorkbookFactory.Create(file); ISheet sheet = workbook.GetSheetAt(0); var cellValue = sheet.GetRow(0).GetCell(0).StringCellValue; return cellValue; } } } ``` 对于 **EPPlus**, 需要注意的是该库依赖于 `System.Drawing.Common`,这可能不完全兼容 IL2CPP 的 AOT 编译模式。因此建议优先考虑 NPOI[^1]。 #### 方法二:基于 CSV 格式的简单解决方案 如果不需要复杂的 Excel 功能,可以选择将数据保存为简单的 CSV 文件格式,并利用 C# 内置的方法来解析这些文件。CSV 文件可以用任何电子表格程序打开和编辑。 ```csharp // 将二维数组导出到 CSV 文件 public static bool ExportArrayToCsv<T>(string path, T[,] array) where T : struct { try { StreamWriter sw = new StreamWriter(path); int rows = array.GetLength(0), cols = array.GetLength(1); for(int i=0;i<rows;++i){ StringBuilder sb=new StringBuilder(); for(int j=0;j<cols;++j){ if(j>0)sb.Append(","); sb.Append(array[i,j]); } sw.WriteLine(sb.ToString()); } sw.Close(); return true; } catch(System.Exception e) { Debug.LogError(e.Message);return false;} } // 从 CSV 导入至二维数组 public static T[,] ImportArrayFromCsv<T>(string path,int rowCount,int colCount) where T : struct{ StreamReader sr=null; try{ sr =new StreamReader(path); char[] delimiters={','}; T[,] result=(T[,]) Array.CreateInstance(typeof(T),rowCount,colCount); for(int r=0;r<rowCount && !sr.EndOfStream ;r++){ string line=sr.ReadLine().TrimEnd('\n').TrimEnd('\r'); string[] values=line.Split(delimiters,System.StringSplitOptions.RemoveEmptyEntries); for(int c=0;c<colCount&&c<values.Length;c++) result[r,c]=(T) Convert.ChangeType(values[c],typeof(T)); } return result; }finally{if(sr!=null)sr.Close();} } ``` 这种方法的优点在于它避免了引入额外的外部依赖项,从而减少了潜在的跨平台问题风险[^2]。 #### 推荐方案 考虑到 IL2CPP 对某些高级框架的支持有限,在此场景下更倾向于推荐使用 NPOI 来完成 Excel 文件的操作需求。因为相比其他选项而言,NPOI 更加轻量级且具有较好的向后兼容性和稳定性[^3]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值