Skip to content

Commit 5da1f12

Browse files
committed
Merge pull request #64 from hypersw/master
Fix ArgumentException from Encoding::GetEncoding() in creating a ZipFile
2 parents 13eed41 + d398b30 commit 5da1f12

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

src/Zip/ZipConstants.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,16 @@ public sealed class ZipConstants
473473
// 850 is a good default for english speakers particularly in Europe.
474474
static int defaultCodePage = CultureInfo.CurrentCulture.TextInfo.ANSICodePage;
475475
#else
476-
static int defaultCodePage = Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage;
476+
/// <remarks>
477+
/// Get OEM codepage from NetFX, which parses the NLP file with culture info table etc etc.
478+
/// But sometimes it yields the special value of 1 which is nicknamed <c>CodePageNoOEM</c> in <see cref="Encoding"/> sources (might also mean <c>CP_OEMCP</c>, but Encoding puts it so).
479+
/// This was observed on Ukranian and Hindu systems.
480+
/// Given this value, <see cref="Encoding.GetEncoding(int)"/> throws an <see cref="ArgumentException"/>.
481+
/// So replace it with some fallback, e.g. 437 which is the default cpcp in a console in a default Windows installation.
482+
/// </remarks>
483+
static int defaultCodePage =
484+
Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage != 1 /* CodePageNoOEM constant, causes ArgumentException in subsequent calls to Encoding::GetEncoding() */ ?
485+
Thread.CurrentThread.CurrentCulture.TextInfo.OEMCodePage : 437 /* The default OEM encoding in a console in a default Windows installation, as a fallback. */;
477486
#endif
478487

479488
/// <summary>

0 commit comments

Comments
 (0)