Bug 39237 - System.NotSupportedException: No data is available for encoding 1252. (incorrect dependencies in 4.4 Debian packages)
Summary: System.NotSupportedException: No data is available for encoding 1252. (incorr...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: packaging ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Jo Shields
URL:
: 40862 41096 ()
Depends on:
Blocks:
 
Reported: 2016-03-01 04:57 UTC by David Lechner
Modified: 2016-06-17 13:34 UTC (History)
10 users (show)

Tags:
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 GitHub or Developer Community 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:
Status:
RESOLVED FIXED

Description David Lechner 2016-03-01 04:57:30 UTC
I'm getting crashing in my mono programs with top of stack trace like this...

System.NotSupportedException: No data is available for encoding 1252.
  at System.Text.Encoding.GetEncoding (Int32 codepage) <0x7f58dce16450 + 0x0053b> in <filename unknown>:0 

Did something change recently?

mono --version
Mono JIT compiler version 4.3.2 (Stable 4.3.2.467/ba2e5e4 Tue Feb 23 12:11:14 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen
Comment 1 Marek Safar 2016-03-05 15:03:15 UTC
I cannot reproduce this. Please provide steps how to reproduce it. Simple sample program works as expected.

using System;

class X
{
	public static void Main ()
	{
		System.Text.Encoding.GetEncoding (1252);
	}
}
Comment 2 David Lechner 2016-03-05 21:52:54 UTC
I just tried this on a fresh install of Ubuntu 14.04 in a VM.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
sudo apt-add-repository "deb http://download.mono-project.com/repo/debian alpha main"
sudo apt-get update
sudo apt-get install monodevelop

* Start MonoDevelop
* Start a new console application
* Use the simple test case above.
* Run the program.
* Crashes with unhanded exception.
System.NotSupportedException: No data is available for encoding 1252.
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00268] in <filename unknown>:0
  at test.MainClass.Main (System.String[] args) [0x00006] in /home/david/work/test/test/Program.cs:9
Comment 3 David Lechner 2016-03-05 22:01:26 UTC
Looking at https://github.com/mono/referencesource/blob/mono-4.3.2-branch/mscorlib/system/text/encoding.cs

Maybe MONO_HYBRID_ENCODING_SUPPORT was not enabled in this build? or FEATURE_CODEPAGES_FILE was enabled?
Comment 4 David Lechner 2016-03-05 22:22:21 UTC
Ah... this is a package dependency problem. mono-devel 4.2.2.30-0xamarin2 depends on libmono-i18n4.0.cil, however mono-devel 4.3.2.467-0xamarin2 does not have this dependency, so the required libmono-i18n4.0.cil package is not installed.
Comment 5 gserg.g 2016-04-06 17:05:16 UTC
FYI, this also breaks System.Data.SqlClient on (at least) Android, because SqlConnection.Open() calls System.Text.Encoding.GetEncoding(1252) and crashes.
Comment 6 Han Zhao 2016-04-09 00:22:40 UTC
Use Xamarin Studio Business to create a new iOS Unified API Unit Test App

namespace EncodingTest
{
	public class Application
	{
		static void Main (string[] args)
		{
			try
			{
				var encoding = System.Text.Encoding.GetEncoding(1252);
			}
			catch (System.Exception e)
			{
				System.Diagnostics.Debug.WriteLine (e.Message);
			}
			//UIApplication.Main (args, null, "UnitTestAppDelegate");
		}
	}
}

Run the code, get the exception message: "No data is available for encoding 1252."

Stack Trace:

  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00214] in /Users/builder/data/lanes/3051/5f11db87/source/maccore/_build/Library/Frameworks/Xamarin.iOS.framework/Versions/git/src/mono/external/referencesource/mscorlib/system/text/encoding.cs:520 
  at EncodingTest.Application.Main (System.String[] args) [0x00007] in /Users/dev/Projects/EncodingTest/EncodingTest/Main.cs:10




=== Xamarin Studio Business ===

Version 5.10.3 (build 51)
Installation UUID:
Runtime:
	Mono 4.2.3 (explicit/832de4b)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402030004

=== Apple Developer Tools ===

Xcode 7.3 (10183.3)
Build 7D175

=== Xamarin.iOS ===

Version: 9.6.1.9 (Xamarin Business)
Hash:
Branch: master
Build date: 2016-03-25 21:26:55-0400

=== Xamarin.Android ===

Version: 6.0.3.5 (Xamarin Business)
Android SDK: /Users/dev/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL

=== Xamarin.Mac ===

Version: 2.4.2.1 (Xamarin Business)

=== Build Information ===

Release ID: 510030051
Git revision:
Build date: 2016-03-24 18:51:31-04
Xamarin addins:
Build lane: monodevelop-lion-cycle6-c6sr3

=== Operating System ===

Mac OS X 10.11.3
15.3.0 Darwin Kernel Version 15.3.0
    Thu Dec 10 18:40:58 PST 2015
    root:xnu-3248.30.4~1/RELEASE_X86_64 x86_64
Comment 7 drobosson 2016-04-12 05:17:50 UTC
I confirm the android behavior that gserg.g is reporting in comment #5.

Installed via Xamarin Universal Installer 3.5.0.0
Xamarin: 4.0.3.214
VS Prof 2015: 14.0.24720.00 Update 1

Logcat stack trace:

D/stuff   (27972): System.NotSupportedException: No data is available for encoding 1252.
D/stuff   (27972):   at System.Text.Encoding.GetEncoding (Int32 codepage) [0x0022d] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.TdsCharset.GetEncodingFromSortOrder (Int32 sortId) [0x00025] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.TdsCharset.GetEncodingFromSortOrder (System.Byte[] collation) [0x00007] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.TdsCharset.GetEncoding (System.Byte[] collation) [0x0000b] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds.ProcessEnvironmentChange () [0x0024f] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x0011f] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds.NextResult () [0x0004a] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00005] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds70.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x005b5] in <filename unknown>:0
D/stuff   (27972):   at Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in <filename unknown>:0
D/stuff   (27972):   at System.Data.SqlClient.SqlConnection.Open () [0x0023b] in <filename unknown>:0


Pseudo code, built in release mode, self signed and adb side loaded to device:

var connectionString = "Data Source=dbHostname.local;Initial Catalog=myDb;Persist Security Info=True;User ID=yours;Password=mine";
using (var connection = new SqlConnection(connectionString))
{
  var command = new SqlCommand("SELECT COUNT(COLUMNNAME) FROM dbo.SomeTable WHERE condition", connection)
  connection.Open(); // EXCEPTION ABOVE IS LOGGED FROM HERE
  var result = (int) command.ExecuteScalar();
}


It should be noted that this problem is not exhibited when building the application in debug mode and deploying the shared runtime in the process prior to installation of the application.
Comment 8 Marek Safar 2016-04-12 09:54:54 UTC
For iOS/Android you need to enable West internationalization codeset in the project settings.
Comment 9 drobosson 2016-04-13 00:44:08 UTC
Confirmed, in release configuration, enabling the additional supported encoding, "West" does result in the expected behavior.
Comment 10 Jo Shields 2016-04-13 14:53:50 UTC
This seems to be two different issues being conflated together by identical results:

* for Xamarin, some value needs to be set in project settings
* on Linux command line, there is some issue with package dependencies

I can only really speak to the latter.

The 1252 codepage is in the package libmono-i18n-west4.0-cil, which is Recommended by libmono-corlib4.5-cil

Recommends is the correct relationship to use when package 1 does not *need* package 2, but is greatly enhanced by it and you probably want it (but might optionally not want it). To this end, the default on every Debian-derived distribution I know of *except* for Linux mint is that Recommends: are installed as if they were Depends:

So try `apt-config dump | grep ^APT::Install-Recommends` in a shell - if you get a 1 or true, then there is a bug to be fixed - in which case please reopen this issue. If you get a 0 or false, then getting this error is user error caused by bypassing the Recommends (and, again, the default behaviour in Apt is to install Recommends)

If your software explicitly needs CP1252, it should have a hard requirement on the I18N.West.dll assembly (e.g. by having a dependency on the libmono-i18n-west4.0-cil package)
Comment 11 David Lechner 2016-04-13 15:53:57 UTC
It looks like there is a packaging bug.

> apt-config dump | grep ^APT::Install-Recommends
> APT::Install-Recommends "true";

I will also open a bug with the software (keepass2) that requires this package.
Comment 12 David Lechner 2016-04-13 15:59:48 UTC
It looks like libmono-i18n4.0.cil is only "Suggests:" for libmono-corlib4.5-cil and libmono-corelib4.0-cil depends on libmonocorlib4.5-cil

$ dpkg -s libmono-corlib4.0-cil
Package: libmono-corlib4.0-cil
Status: install ok installed
Priority: optional
Section: cli-mono
Installed-Size: 61
Maintainer: Debian Mono Group <pkg-mono-group@lists.alioth.debian.org>
Architecture: all
Source: mono
Version: 4.4.0.40-0xamarin1
Depends: libmono-corlib4.5-cil (= 4.4.0.40-0xamarin1)
Description: Mono core library (transitional package)
 Mono is a platform for running and developing applications based on the
 ECMA/ISO Standards. Mono is an open source effort led by Xamarin.
 Mono provides a complete CLR (Common Language Runtime) including compiler and
 runtime, which can produce and execute CIL (Common Intermediate Language)
 bytecode (aka assemblies), and a class library.
 .
 This is a transitional package to satisfy dependencies on the older version
 of the Core Library (mscorlib.dll) of Mono for CLI 4.0, which will execute
 fine on the newer 4.5 Core Library.
Homepage: http://www.mono-project.com/

$ dpkg -s libmono-corlib4.5-cil
Package: libmono-corlib4.5-cil
Status: install ok installed
Priority: optional
Section: cli-mono
Installed-Size: 3738
Maintainer: Debian Mono Group <pkg-mono-group@lists.alioth.debian.org>
Architecture: all
Source: mono
Version: 4.4.0.40-0xamarin1
Depends: mono-runtime (>= 4.4.0.40), mono-runtime (<< 4.4.0.41)
Recommends: libmono-i18n-west4.0-cil
Suggests: libmono-i18n4.0-all
Description: Mono core library (for CLI 4.5)
 Mono is a platform for running and developing applications based on the
 ECMA/ISO Standards. Mono is an open source effort led by Xamarin.
 Mono provides a complete CLR (Common Language Runtime) including compiler and
 runtime, which can produce and execute CIL (Common Intermediate Language)
 bytecode (aka assemblies), and a class library.
 .
 This package contains the Core Library (mscorlib.dll) of Mono for CLI 4.5,
 which is the glue between the BCL (Base Class Libraries) and the JIT.
 .
 You should install libmono-i18n-west4.0-cil if you are using
 ISO 8859-15 (Latin 9) or other common Western European code pages.
 US-ASCII, ISO 8859-1 (Latin 1) and UTF-8 users don't need any extra I18N
 packages.
Homepage: http://www.mono-project.com/
Comment 13 Jo Shields 2016-04-13 16:05:37 UTC
libmono-i18n-west4.0-cil is the package you need for CP1252, not libmono-i18n4.0.cil

See the package description for libmono-corlib4.5-cil itself - "You should install libmono-i18n-west4.0-cil if you are using ISO 8859-15 (Latin 9) or other common Western European code pages. US-ASCII, ISO 8859-1 (Latin 1) and UTF-8 users don't need any extra I18N packages"
Comment 14 David Lechner 2016-04-13 17:02:51 UTC
Apparently libmono-i18n-west4.0-cil does not contain the Windows 1252 codepage - or at least not the part that KeePass is looking for. I have just updated to 4.4.0.122-0xamarin1 and it is still crashes without libmono-i18n-4.0-cil installed...

> $ dpkg -s libmono-i18n-west4.0-cil | grep Status
> Status: install ok installed
> $ dpkg -s libmono-i18n4.0-cil
> dpkg-query: package 'libmono-i18n4.0-cil' is not installed and no information is available
...

> $ keepass2
...

> System.NotSupportedException: No data is available for encoding 1252.
...


If I install libmono-i18n-4.0-cil, all is well.
Comment 15 David Lechner 2016-04-13 17:03:50 UTC
libmono-i18n4.0-cil says "This package also includes the base I18N library used by all I18N libraries.", so maybe other i18n packages should depend on this package?


$ dpkg -s libmono-i18n4.0-cil
Package: libmono-i18n4.0-cil
Status: install ok installed
Priority: optional
Section: cli-mono
Installed-Size: 124
Maintainer: Debian Mono Group <pkg-mono-group@lists.alioth.debian.org>
Architecture: all
Source: mono
Version: 4.4.0.122-0xamarin1
Depends: mono-devel (>= 1.0), mono-runtime (>= 4.4.0.122), mono-runtime (<< 4.4.0.123)
Description: Mono I18N base library (for CLI 4.0)
 Mono is a platform for running and developing applications based on the
 ECMA/ISO Standards. Mono is an open source effort led by Xamarin.
 Mono provides a complete CLR (Common Language Runtime) including compiler and
 runtime, which can produce and execute CIL (Common Intermediate Language)
 bytecode (aka assemblies), and a class library.
 .
 This package also includes the base I18N library used by all I18N
 libraries.
Homepage: http://www.mono-project.com/
Comment 16 David 2016-05-02 11:35:06 UTC
I have this problem using ServiceStack connected to a MsSql Db

2016-05-02 13:27:46.7814 - ERROR: ServiceBase<TRequest>::Service Exception
EXCEPTION: System.NotSupportedException: No data is available for encoding 1252.
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00268] in <filename unknown>:0 
  at Mono.Data.Tds.TdsCharset.GetEncodingFromSortOrder (Int32 sortId) [0x00025] in <filename unknown>:0 
  at Mono.Data.Tds.TdsCharset.GetEncodingFromSortOrder (System.Byte[] collation) [0x00007] in <filename unknown>:0 
  at Mono.Data.Tds.TdsCharset.GetEncoding (System.Byte[] collation) [0x0000b] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds.ProcessEnvironmentChange () [0x0024f] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds.ProcessSubPacket () [0x0011f] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds.NextResult () [0x0004a] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds.SkipToEnd () [0x00005] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds70.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x005b5] in <filename unknown>:0 
  at Mono.Data.Tds.Protocol.Tds80.Connect (Mono.Data.Tds.Protocol.TdsConnectionParameters connectionParameters) [0x00000] in <filename unknown>:0 
  at System.Data.SqlClient.SqlConnection.Open () [0x0023b] in <filename unknown>:0 


I've got this problem after updating ubuntu to 16.04 from 14.04.
Comment 17 David 2016-05-02 12:46:29 UTC
Sorry for lack of information 

Mono JIT compiler version 4.4.0 (Stable 4.4.0.122/a3fabf1 Tue Apr 12 17:44:06 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       altstack
        Notifications: epoll
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug 
        LLVM:          supported, not enabled.
        GC:            sgen
Comment 18 David Lechner 2016-05-02 15:45:24 UTC
Is it fixed by running this command? 

    sudo apt-get install libmono-i18n-4.0-cil
Comment 19 David 2016-05-03 05:14:36 UTC
No its fixed! I installed a previous version for now!
Comment 20 Jo Shields 2016-05-10 15:26:39 UTC
*** Bug 40862 has been marked as a duplicate of this bug. ***
Comment 21 Jo Shields 2016-05-10 16:38:19 UTC
OK, so.

This is *tangentially* related to the -api rename (i.e. /usr/lib/mono/4.5/ contains Mono libs, /usr/lib/mono/4.5-api/ contains facades for compilation)

During package building, dh_makeclilibs looks at all assemblies, determines which are "real" assemblies, and generates an assembly->packagename mapping file. This mapping file is used by dh_clideps to determine which intra-package dependencies to include.

Due to reasons, /usr/lib/mono/4.5-api/I18N.dll is a real assembly, not a metadata-only facade, and dh_makeclilibs was creating a mapping for I18N 4.0.0.0 -> mono-devel

dh_clideps was picking up this mapping instead of the libmono-i18n4.0-cil one.

I'll push a fix out to the alpha repo as soon as possible.
Comment 22 Leonid Vasilyev 2016-05-18 14:24:17 UTC
This resolve the issue in my case. But there is a typo, package name is libmono-i18n4.0-cil
Comment 23 Marek Safar 2016-05-25 08:47:32 UTC
*** Bug 41096 has been marked as a duplicate of this bug. ***