To distribute our application without requiring the user to install the mono framework, we use MonoKickstart to dynamically link the Mono libraries on runtime. We are using the Ionic.Zip library to extract an archive when the application starts. By default, this library uses the IBM437 encoding. However, it is unable to load this encoding as can be seen by the following exception:
System.NotSupportedException: No data is available for encoding 437.
at System.Text.Encoding.GetEncoding (Int32 codepage) <0x10a0d9970 + 0x0076e> in <filename unknown>:0
This default encoding is statically initialised, so even though we specify a different encoding, the exception still occurs.
If we include the I18N.dll and I18N.West.dll libraries to the dynamically loaded library, the following exception occurs:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidProgramException: Invalid IL code in I18N.Common.Manager:get_PrimaryManager (): IL_0000: ret
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x11b3340e0 + 0x000bb> in <filename unknown>:0
--- End of inner exception stack trace ---
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x11b3340e0 + 0x00139> in <filename unknown>:0
at System.RuntimeType.InvokeMember (System.String name, BindingFlags bindingFlags, System.Reflection.Binder binder, System.Object target, System.Object[] providedArgs, System.Reflection.ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, System.String[] namedParams) <0x11b332300 + 0x011b7> in <filename unknown>:0
at System.Text.EncodingHelper.InvokeI18N (System.String name, System.Object[] args) <0x11b32fa10 + 0x00317> in <filename unknown>:0
at System.Text.Encoding.GetEncoding (Int32 codepage) <0x111378970 + 0x00671> in <filename unknown>:0
We are also unable to create the encoding on our own, so that is definitely the issue.
Is there a way to fix the loading of the encoding by adding the right libraries, or alternatively can we somehow prevent the encoding from being initialised altogether (without recompiling the library for ourselves).
The list of dlls we currently load dynamically is:
Ionic.Zip.Reduced.dll
Mono.Posix.dll
Mono.Security.dll
mscorlib.dll
System.Configuration.dll
System.Core.dll
System.Data.dll
System.dll
System.Drawing.dll
System.Net.dll
System.Numerics.dll
System.Runtime.Serialization.dll
System.Security.dll
System.Xml.dll
System.Xml.Linq.dll
WindowsBase.dll
Directly from the page Hans linked:
When including 3rd party libraries in your Xamarin.Mac app, you might get an error in the form "System.NotSupportedException: No data is available for encoding 437" when trying to compile and run the app. For example, libraries, such as Ionic.Zip.ZipFile, may throw this exception during operation.
This can be solved by opening the options for the Xamarin.Mac project, going to Mac Build > Internationalization and checking the West internationalization:
Works for both Mac projects and iOS. Also, be sure to have it checked on both Debug and Release (if releasing the app to the app store).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With