Bug 20582 - Compute method of System.Data.DataTable not using Invariant Culture to evaluate expressions
Summary: Compute method of System.Data.DataTable not using Invariant Culture to evalua...
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: System.Data ()
Version: unspecified
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Marek Safar
URL:
Depends on:
Blocks:
 
Reported: 2014-06-13 10:59 UTC by Allie Miller
Modified: 2014-08-06 11:51 UTC (History)
5 users (show)

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


Attachments
Update to System.Data (373.98 KB, application/zip)
2014-06-24 13:16 UTC, Sebastien Pouliot
Details


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 Allie Miller 2014-06-13 10:59:14 UTC
When changing a device's region format, the following error is generated when the compute method of System.Data.DataTable is evaluating an expression: 

>>System.FormatException: Unknown char: .

>>at System.Double.Parse (System.String s, NumberStyles style, IFormatProvider provider) [0x00012] in >>/Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Double.cs:229 

>>at System.Double.Parse (System.String s) [0x00000] in >>/Developer/MonoTouch/Source/mono/mcs/class/corlib/System/Double.cs:200 

>>at Mono.Data.SqlExpressions.Tokenizer.ReadNumber () [0x0006e] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/Mono.Data.SqlExpressions/Tokenizer.cs:142 

>>at Mono.Data.SqlExpressions.Tokenizer.ParseToken () [0x00107] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/Mono.Data.SqlExpressions/Tokenizer.cs:340 

>>at Mono.Data.SqlExpressions.Tokenizer.advance () [0x0000d] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/Mono.Data.SqlExpressions/Tokenizer.cs:361 

>>at Mono.Data.SqlExpressions.Parser.yyparse (yyInput yyLex) [0x00125] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/Mono.Data.SqlExpressions/Parser.cs:341 

>>at Mono.Data.SqlExpressions.Parser.Compile (System.String sqlExpr) [0x00029] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/Mono.Data.SqlExpressions/Parser.cs:51 

>>at System.Data.DataTable.Compute (System.String expression, System.String filter) [0x00023] in >>/Developer/MonoTouch/Source/mono/mcs/class/System.Data/System.Data/DataTable.cs:803 

However, when the region is set to the current culture of the device, it will return a value.

*To reproduce

1) In a Xamarin.iOS project, add the following:

DataTable dt = new DataTable();
dt.Columns.Add("xxx", typeof(int));
dt.Rows.Add(1);

var test = dt.Compute("4.5", null); 

2) Run the project to observe that the value is returned

3) Remove the application from the device and change the region format to Bulgarian.

4) Deploy to the device again to observe the invalid character error


*Versioning Information
=== Xamarin Studio ===
Version 4.2.3 (build 60)
Installation UUID: c3fb9926-4ae4-4f38-9ddf-04578ff14659
Runtime:
Mono 3.2.6 ((no/9b58377)
GTK+ 2.24.23 theme: Raleigh
GTK# (2.12.0.0)
Package version: 302060000
=== Apple Developer Tools ===
Xcode 5.1.1 (5085)
Build 5B1008
=== Xamarin.iOS ===
Version: 7.2.0.2 (Enterprise Edition)
Hash: 58c3efa
Branch: 
Build date: 2014-10-03 18:02:26-0400
Operating System
Mac OS X 10.8.5
Comment 1 Ram Chandra 2014-06-13 14:25:17 UTC
I have check this issue and I am able to reproduce this issue.

Steps to reproduce:

1. Open the iphone's "Single View Application" on XS.
2. Paste the following code inside the "Main()" method of "Main.cs" file.
                        
                        var currentCulture = CultureInfo.CurrentCulture;
			DataTable dt = new DataTable();
			dt.Columns.Add("xxx", typeof(int));
			dt.Rows.Add(1);
          		var test = dt.Compute("4.5", null);

3. Debug the application.
4. Change the region of device (Settings=>General=> International=> Region Format).
5. Debug the application again.

I observed that when I change region of device from "United States" to "Ukrainian (Ukraine)" I am getting an exception i.e "System.FormatException: Unknown char".

I also observed that when I changed region to (UK,India,Chinese) I am not getting this exception.

Screencast: http://www.screencast.com/t/lUg9sVfKq

Environment Info:

Mac OS X 10.9.2
Xamarin Studio: 5.0.1 (build 3)
Xamarin.iOS: 7.2.3.39 (Business Edition)

Build Information
Release ID: 500010003
Git revision: f94ee866936d25105704eb63728ad5a981eda0a4
Build date: 2014-06-04 12:19:12-04
Xamarin addins: 1a6044e8321ea07e03a56b5381951686c82fed8b
Comment 2 Loukas 2014-06-16 02:42:26 UTC
The problem is that the Compute Method of DataTable does not use the Invariant Culture to Evaluate the expression but the CurrentCulture of the device.

it is clearly documented here

http://msdn.microsoft.com/en-us/library/system.data.datacolumn.expression.aspx 

"Parsing Literal Expressions

All literal expressions must be expressed in the invariant culture locale. When DataSet parses and converts literal expressions, it always uses the invariant culture, not the current culture."
Comment 3 Marek Safar 2014-06-16 06:08:19 UTC
Fixed in master
Comment 4 Sebastien Pouliot 2014-06-24 13:16:26 UTC
Created attachment 7167 [details]
Update to System.Data

I just attached an updated System.Data assembly (and symbols) so you can validate that the fix works and is complete. You can keep this assembly as long as you're using XI 7.2.x versions.

To use the attached assembly (on top of MonoTouch 7.2.x) do:

1) Backup your /Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll and /Developer/MonoTouch/usr/lib/mono/2.1/System.Data.dll.mdb files

2) Unzip and copy the attached files to /Developer/MonoTouch/usr/lib/mono/2.1/

3) Clean, rebuild and test your application
Comment 6 Ram Chandra 2014-08-06 11:51:33 UTC
I have checked this issue with following builds:

Mac OS X 10.9.3
Xamarin Studio: 5.3 (build 413)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
	Mono 3.8.0 ((no/9ffca33)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000002

Xamarin.iOS: 7.4.0.89 (Trial Edition)
Build Information
Release ID: 503000413
Git revision: 0b0a22314801b920383045d46a578c716f55e481
Build date: 2014-08-06 04:53:22-04
Xamarin addins: 57e379e6a9454a1c0d97aa3f770e7ae7cc16c522

To verify this issue, I have follow the steps mentioned "comment 1" and observed that when when I change region of device from "United States" to "Ukrainian (Ukraine)" I am not  getting any exception.

This issue has been fixed. Hence, I am closing this issue.