Bug 36154 - TypeInitializationException when creating an instance of Ionic.Zip.ZipFile
Summary: TypeInitializationException when creating an instance of Ionic.Zip.ZipFile
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Runtime ()
Version: 2.4.0 (C6)
Hardware: PC Mac OS
: Normal normal
Target Milestone: 2.8.0 (C7)
Assignee: Chris Hamons
: 36318 ()
Depends on:
Reported: 2015-11-23 11:03 UTC by Greg Munn
Modified: 2015-12-22 15:01 UTC (History)
5 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Greg Munn 2015-11-23 11:03:00 UTC
I'm getting this exception whenever I try to open a zip file with DotNetZip. This used to to work previously - will update bug when I find the version that works again.

System.TypeInitializationException: The type initializer for 'Ionic.Zip.ZipFile' threw an exception. ---> System.NotSupportedException: No data is available for encoding 437.
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00214] in /Library/Frameworks/Xamarin.Mac.framework/Versions/
  at System.Text.Encoding.GetEncoding (System.String name) [0x00000] in /Library/Frameworks/Xamarin.Mac.framework/Versions/
  at Ionic.Zip.ZipFile..cctor () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at ZipTest.AppDelegate.DidFinishLaunching (Foundation.NSNotification notification) [0x00006] in /Users/greg/Projects/Scratch/ZipTest/ZipTest/AppDelegate.cs:18
  at at (wrapper managed-to-native) AppKit.NSApplication:NSApplicationMain (int,string[])
  at AppKit.NSApplication.Main (System.String[] args) [0x00041] in /Users/builder/data/lanes/2097/815e5d67/source/maccore/src/AppKit/NSApplication.cs:94
  at ZipTest.MainClass.Main (System.String[] args) [0x00007] in /Users/greg/Projects/Scratch/ZipTest/ZipTest/Main.cs:10


1. Create a new X.Mac app
2. Change Framework to Xamarin.Mac .NET 4.5 Framework
3. Add DotNetZip nuget
4. Add a line in AppDelegate.DidFinishLaunching like the following
    var zip = new ZipFile (@"/Users/greg/Test.zip");

For reference, I created the zip using Mac's "Compress Items" command in Finder. Same result on both Yosemite and El Capitan.


=== Xamarin Studio ===

Version 5.10 (build 871)
Installation UUID: 4c80d01a-1a3a-4aa8-88c0-c96149a20e81
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.1.1 (9081)
Build 7B1005

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 3c0ec35
Branch: master
Build date: 2015-11-12 13:05:39-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/greg/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3   (API level 10)
		4.0.3 (API level 15)
		4.4   (API level 19)
		5.0   (API level 21)
		5.1   (API level 22)
		6.0   (API level 23)

SDK Tools Version: 24.3.4
SDK Platform Tools Version: 23
SDK Build Tools Version: 22.0.1

Java SDK: /usr
java version "1.7.0_75"
Java(TM) SE Runtime Environment (build 1.7.0_75-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.75-b04, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 510000871
Git revision: 4e9c5abb5ffdae12ba02ac49da83f8b2011dbb88
Build date: 2015-11-12 06:02:54-05
Xamarin addins: 55007ed0e56436f385d8e26394a45be563abc7e8
Build lane: monodevelop-lion-cycle6

=== Operating System ===

Mac OS X 10.10.5
Darwin Kryten.local 14.5.0 Darwin Kernel Version 14.5.0
    Tue Sep  1 21:23:09 PDT 2015
    root:xnu-2782.50.1~1/RELEASE_X86_64 x86_64
Comment 1 Greg Munn 2015-11-23 11:06:54 UTC
X.M 2.02 creates the instance of the ZipFile as expected.
Comment 2 Chris Hamons 2015-11-30 19:23:35 UTC
*** Bug 36318 has been marked as a duplicate of this bug. ***
Comment 3 Chris Hamons 2015-11-30 19:25:23 UTC
^ appears to be an identical bug, though it is using System.IO.Compresion.ZipFile.ExtractToDirectory instead of DotNetZip.
Comment 4 Chris Hamons 2015-11-30 19:33:59 UTC
Copying these files into the mono bundle "fix" the problem:

Loaded assembly: /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/gac/I18N/
Loaded assembly: /Library/Frameworks/Mono.framework/Versions/4.2.1/lib/mono/gac/I18N.West/

^ is not a suggested work around. If your version of mono doesn't exactly match the one bundled with XM, then "bad things" may occur at runtime. 

The XM 4.5 profile needs to include I18N.dll and friends apparently.
Comment 5 Chris Hamons 2015-11-30 19:39:39 UTC
Apparently we _do_ ship those assemblies, just mmp isn't pulling them in.

A valid work around is to add the following lines to your csproj:

    <Reference Include="I18N">
    <Reference Include="I18N.West">

Or you can add a reference in XS and browse to that location manually.
Comment 6 Greg Munn 2015-11-30 19:48:28 UTC
thanks for the workaround.
Comment 7 Rodrigo Kumpera 2015-12-17 21:07:52 UTC
Hey Koeplinger,

Could you take a look at this one. Mono seems to be misbehaving.
Comment 8 Miguel de Icaza [MSFT] 2015-12-18 02:19:25 UTC
This looks like a case of the new framework code using the new codepage.

As discussed on the mailing list, I think that we want is to remove the dependency on this codepage, as opposed to adding the codepage decoder.
Comment 9 Miguel de Icaza [MSFT] 2015-12-18 02:27:41 UTC
I take it back, this is not the reference source code, this is embedded into Ionic's zip library.

The correct solution is just to bundle the I18N's West assemblies.   If we have a bug bundling them, we should fix that, but it is not a Mono issue.
Comment 10 Chris Hamons 2015-12-18 02:50:32 UTC
There is no bug bundling them if you check the correct box in the project configuration, it will pull in West for you and all will be well. 

Now, if that should be the default, and/or we should a better error message are open questions.
Comment 11 Chris Hamons 2015-12-18 02:50:37 UTC
There is no bug bundling them if you check the correct box in the project configuration, it will pull in West for you and all will be well. 

Now, if that should be the default, and/or we should a better error message are open questions.
Comment 12 Miguel de Icaza [MSFT] 2015-12-18 03:40:56 UTC
I think the default is fine, and we should just make the answer googable.
Comment 13 Chris Hamons 2015-12-21 17:02:41 UTC
Working with documentation to get this posted somewhere. Will close bug when it is public.
Comment 14 Chris Hamons 2015-12-22 15:01:42 UTC
This is now documented here:


I'm going to close as answered, as people who run into this case will be instructed to just enable the west checkbox.