Quantcast
Channel: NPOI
Viewing all articles
Browse latest Browse all 1621

Commented Issue: Error when running NPOI with Mono C# compiler version 2.0.1.0 [4547]

$
0
0
<p>Dear developers,</p>
<p>&nbsp;</p>
<p>I get an error when running applications using NPOI under mono: </p>
<p>&nbsp;</p>
<p>Unhandled Exception: System.ArgumentException: Encoding name &#39;UTF-16LE&#39; not supported</p>
<p>Parameter name: name</p>
<p> at System.Text.Encoding.GetEncoding (System.String name) [0x00000] </p>
<p> at NPOI.Util.StringUtil.PutUnicodeLE (System.String input, System.Byte[] output, Int32 offset) [0x00000]</p>
<p>&nbsp;</p>
<p>Thank you for help,</p>
<p>h2o</p>

Comments: ** Comment from web user: firda **

I have changed it to this while MONO is defined and GOOD_MONO is not (UTF-16 is obviously not working under mono as it should, it is actually working as UTF-16LE which means UTF-16 without BOM)

public static void PutUnicodeLE(String input, byte[] output, int offset)
{
#if !MONO
byte[] bytes = Encoding.GetEncoding("UTF-16LE").GetBytes(input);
Array.Copy(bytes, 0, output, offset, bytes.Length);
#elif GOOD_MONO
byte[] bytes = Encoding.GetEncoding("UTF-16").GetBytes(input);
Array.Copy(bytes, 2, output, offset, bytes.Length - 2);
#else
byte[] bytes = Encoding.GetEncoding("UTF-16").GetBytes(input);
Array.Copy(bytes, 0, output, offset, bytes.Length);
#endif
}
public static void PutUnicodeLE(String input, ILittleEndianOutput out1)
{
byte[] bytes;
try
{
#if !MONO
bytes = Encoding.GetEncoding("UTF-16LE").GetBytes(input);
#else
bytes = Encoding.GetEncoding("UTF-16").GetBytes(input);
#endif
}
catch (EncoderFallbackException)
{
throw;
}
#if !MONO || !GOOD_MONO
out1.Write(bytes);
#else
out1.Write(bytes, 2, bytes.Length - 2);
#endif
}


Viewing all articles
Browse latest Browse all 1621

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>