Mono环境下不支持Encoding.GetEncoding("GB2312")的解决方法

本文详细介绍了如何解决mono-locale-extras缺失导致的编码问题,并提供了安装该组件的具体步骤。通过安装mono-locale-extras,可以解决在使用不同编码时遇到的兼容性问题。

转载自:http://www.cnblogs.com/muse/articles/1756821.html

mono-locale-extras

可以先写一句测试代码:

 

EncodingInfo[] enc = Encoding.GetEncodings();

在这行上设置一个断点,可以浏览到所有可用的编码名称/CodePage。这时看到936——也就是GB2312的的CodePage被标明为未实现的。

启动YaST安装软件,在“全部”组里检索mono关键字,找到mono-locale-extras。文件列表如下:

/usr/lib/mono/1.0

I18N.CJK.dll, I18N.MidEast.dll, I18N.Other.dll, I18N.Rare.dll
/usr/lib/mono/2.0
I18N.CJK.dll, I18N.MidEast.dll, I18N.Other.dll, I18N.Rare.dll
/usr/lib/mono/gac/I18N.CJK/1.0.5000.0__0738eb9f132ed756
I18N.CJK.dll, I18N.CJK.dll.mdb
/usr/lib/mono/gac/I18N.CJK/2.0.0.0__0738eb9f132ed756
I18N.CJK.dll, I18N.CJK.dll.mdb
/usr/lib/mono/gac/I18N.MidEast/1.0.5000.0__0738eb9f132ed756
I18N.MidEast.dll, I18N.MidEast.dll.mdb
/usr/lib/mono/gac/I18N.MidEast/2.0.0.0__0738eb9f132ed756
I18N.MidEast.dll, I18N.MidEast.dll.mdb
/usr/lib/mono/gac/I18N.Other/1.0.5000.0__0738eb9f132ed756
I18N.Other.dll, I18N.Other.dll.mdb
/usr/lib/mono/gac/I18N.Other/2.0.0.0__0738eb9f132ed756
I18N.Other.dll, I18N.Other.dll.mdb
/usr/lib/mono/gac/I18N.Rare/1.0.5000.0__0738eb9f132ed756
I18N.Rare.dll, I18N.Rare.dll.mdb
/usr/lib/mono/gac/I18N.Rare/2.0.0.0__0738eb9f132ed756
I18N.Rare.dll, I18N.Rare.dll.mdb

选中mono-locale-extras后点击Install,一路next就可以了。有依赖关系的软件包会自动安装。当你在mono网站下载安装mono开发环境的时候,安装软件会自动在软件管理器中添加mono的源。如果没有找到mono-locale-extras,确认一下是否已经添加了以下软件安装源:

MonoDevelop : http://monodevelop.com/files/Linux/releases/openSUSE_11.2/

mono-stable : http://ftp.novell.com/pub/mono/download-stable/openSUSE_11.2

 

然后再看一下上面那行代码的断点时候的结果。Have funs。

------------------------------------------------------------------

补充一点:如果仅仅是通用代码的话并无什问题。如果将使用了locale编码的对象序列化存储后,在win平台下反序列化的时候,是无法将其反序列化的。也就是说,虽然代码是一致的,但其实使用的是另外的程序集在实现这些代码。

Mono path[0] = 'D:/抽签程序/抽签程序_Data/Managed' Mono config path = 'D:/抽签程序/MonoBleedingEdge/etc' Found 1 interfaces on host : 0) 192.168.2.9 Multi-casting "[IP] 192.168.2.9 [Port] 55000 [Flags] 2 [Guid] 2337103870 [EditorId] 274872599 [Version] 1048832 [Id] WindowsPlayer(2,HYGK-PC) [Debug] 1 [PackageName] WindowsPlayer [ProjectName] 抽签程序" to [225.0.0.222:54997]... Starting managed debugger on port 56870 Using monoOptions --debugger-agent=transport=dt_socket,embedding=1,server=y,suspend=n,address=0.0.0.0:56870 AS: AutoStreaming module initializing. [Physics::Module] Initialized MultithreadedJobDispatcher with {0} workers. Initialize engine version: 2021.3.45f1c2 (60b1a63e558a) [Subsystems] Discovering subsystems at path D:/抽签程序/抽签程序_Data/UnitySubsystems GfxDevice: creating device client; threaded=1; jobified=1 Direct3D: Version: Direct3D 11.0 [level 11.1] Renderer: NVIDIA GeForce RTX 4070 (ID=0x2786) Vendor: NVIDIA VRAM: 12012 MB Driver: 32.0.15.7260 Begin MonoManager ReloadAssembly - Completed reload, in 0.063 seconds <RI> Initializing input. XInput1_3.dll not found. Trying XInput9_1_0.dll instead... <RI> Input initialized. <RI> Initialized touch support. UnloadTime: 0.887300 ms NotSupportedException: Encoding 1252 data could not be found. Make sure you have correct international codeset assembly installed and enabled. at System.Text.Encoding.GetEncoding (System.Int32 codepage) [0x0022d] in <34c8028f8a3946349d8f0d77e409a1ae>:0 at ExcelDataReader.ExcelReaderConfiguration..ctor () [0x00000] in <094c3e7b0609403782ec81f6ef498e91>:0 at ExcelDataReader.ExcelReaderFactory.CreateReader (System.IO.Stream fileStream, ExcelDataReader.ExcelReaderConfiguration configuration) [0x00003] in <094c3e7b0609403782ec81f6ef498e91>:0 at ReadExcel.ReadExcelType (ExcelType excelType) [0x00024] in D:\UnityItem\抽签程序\Assets\Scripts\ReadExcel.cs:87 at ReadExcel.Start () [0x00034] in D:\UnityItem\抽签程序\Assets\Scripts\ReadExcel.cs:54 (Filename: D:/UnityItem/抽签程序/Assets/Scripts/ReadExcel.cs Line: 87) 什么问题
10-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值