473,326 Members | 2,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Why does 20, 20 not "ConvertFrom" in Norwegian, but does in English?

(note, this is a C# or VB.NET ambivalent question....)
Hi,

Have a slight problem with a library I'm using here (which I have the source
code for). It has data files serialized with an English ("en") locale, but
I'm trying to de-serialize with a Norwegian ("no") locale. The issue is
with the SizeConvertor class. Consider:

protected static SizeConverter _sc = new SizeConverter();

public static Size StringToSize(string str)
{
return (Size)_sc.ConvertFrom(str);
}

When str = "20, 20" and using `en' locale, the result is a returned Size of
20, 20. However, when using the `no' Norwegian locale, the result is a
thrown exception:

`Message "20 is not a valid value for Int32." String'

The inner exception says:

`Input string was not in a correct format.'


Now, if I change the above to:

public static Size StringToSize(string str)
{
return (Size)_sc.ConvertFrom(null, new
System.Globalization.CultureInfo("en"), str);
}
, in order to get a conversion using the locale the file was created with, I
get a different [inner] exception:

'Culture `en' is a neutral culture. It can not be used in formatting and
parsing and therefore cannot be set as the thread's current culture.'

Can anyone tell me what gives here? How can I read resources created with
"en" back in with "en" parsing when using Norwegian (or
_insert_other_ui_locale_here_)?

Thanks,


Robin

Nov 17 '05 #1
2 1549
I got it - I need to use System.Globalization.CultureInfo.InvariantCulture
:))

"Robin Tucker" <un********@duetospam.com> wrote in message
news:de*******************@news.demon.co.uk...
(note, this is a C# or VB.NET ambivalent question....)
Hi,

Have a slight problem with a library I'm using here (which I have the
source code for). It has data files serialized with an English ("en")
locale, but I'm trying to de-serialize with a Norwegian ("no") locale.
The issue is with the SizeConvertor class. Consider:

protected static SizeConverter _sc = new SizeConverter();

public static Size StringToSize(string str)
{
return (Size)_sc.ConvertFrom(str);
}

When str = "20, 20" and using `en' locale, the result is a returned Size
of 20, 20. However, when using the `no' Norwegian locale, the result is a
thrown exception:

`Message "20 is not a valid value for Int32." String'

The inner exception says:

`Input string was not in a correct format.'


Now, if I change the above to:

public static Size StringToSize(string str)
{
return (Size)_sc.ConvertFrom(null, new
System.Globalization.CultureInfo("en"), str);
}
, in order to get a conversion using the locale the file was created with,
I get a different [inner] exception:

'Culture `en' is a neutral culture. It can not be used in formatting
and parsing and therefore cannot be set as the thread's current culture.'

Can anyone tell me what gives here? How can I read resources created with
"en" back in with "en" parsing when using Norwegian (or
_insert_other_ui_locale_here_)?

Thanks,


Robin

Nov 17 '05 #2
Hello Robin,

That happens because the comma is the decimal separator in Norwegian. In that circumstance, the comma is not a valid list separator for numbers, as the conversion is seeing something like "20. 20" in English, which is not a valid number.

Using InvariantCulture or US culture, wich is the same, allows you to use the same string in any culture, as you discovered.

Regards.
"Robin Tucker" <un********@duetospam.com> escribió en el mensaje news:de*******************@news.demon.co.uk...
|I got it - I need to use System.Globalization.CultureInfo.InvariantCulture
| :))
|
| "Robin Tucker" <un********@duetospam.com> wrote in message
| news:de*******************@news.demon.co.uk...
| > (note, this is a C# or VB.NET ambivalent question....)
| >
| >
| > Hi,
| >
| > Have a slight problem with a library I'm using here (which I have the
| > source code for). It has data files serialized with an English ("en")
| > locale, but I'm trying to de-serialize with a Norwegian ("no") locale.
| > The issue is with the SizeConvertor class. Consider:
| >
| > protected static SizeConverter _sc = new SizeConverter();
| >
| > public static Size StringToSize(string str)
| > {
| > return (Size)_sc.ConvertFrom(str);
| > }
| >
| > When str = "20, 20" and using `en' locale, the result is a returned Size
| > of 20, 20. However, when using the `no' Norwegian locale, the result is a
| > thrown exception:
| >
| > `Message "20 is not a valid value for Int32." String'
| >
| > The inner exception says:
| >
| > `Input string was not in a correct format.'
| >
| >
| >
| >
| > Now, if I change the above to:
| >
| >
| >
| > public static Size StringToSize(string str)
| > {
| > return (Size)_sc.ConvertFrom(null, new
| > System.Globalization.CultureInfo("en"), str);
| > }
| >
| >
| > , in order to get a conversion using the locale the file was created with,
| > I get a different [inner] exception:
| >
| > 'Culture `en' is a neutral culture. It can not be used in formatting
| > and parsing and therefore cannot be set as the thread's current culture.'
| >
| >
| >
| > Can anyone tell me what gives here? How can I read resources created with
| > "en" back in with "en" parsing when using Norwegian (or
| > _insert_other_ui_locale_here_)?
| >
| >
| >
| > Thanks,
| >
| >
| >
| >
| > Robin
| >
| >
| >
|
|
Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: bob | last post by:
Hello, I have a property that I want to show a drop down list box in the property grid. The choices to be shown are a collection of objects. I implment a type convertor that has...
4
by: CroDude | last post by:
I've made a custom groupbox control. Inside, as one of it's members is CSimpleGradient object. CSimpleGradient is a wrapper class for gradient usage. Basically it looks like that: public class...
0
by: Tom | last post by:
I am developing a page that will contain multiple instances of a Composite Custom Control that i have developed. The problem is that the user will determine at run time how many of the control...
0
by: Ewart MacLucas | last post by:
generated some WMI managed classes using the downloadable extensions for vs2003 from mircrosoft downloads; wrote some test code to enumerate the physicall processors and it works a treat, but a...
3
by: Marco Castro | last post by:
I have a picture stored in an ole field in one of my access databases. Im trying to put that picture into a picture box in one of my vb.net programs. Unfortunately I keep on getting a type cast...
2
by: Robin Tucker | last post by:
(note, this is a C# or VB.NET ambivalent question....) Hi, Have a slight problem with a library I'm using here (which I have the source code for). It has data files serialized with an...
2
by: Lespaul36 | last post by:
I have a control that I have made that uses a custom class for storage of some of the information. I want it to display in the VS.Net 2003 property grid in the IDE like the Font property does, so...
4
by: Sharon | last post by:
I'm using an xml schema (XSD) that has a point data in it, so when I'm saving the schema (from memory with values) to an XML file, the point value is saved in the form of: "{X=12, Y=34}" And that...
1
by: Peter Morris | last post by:
Hi all, I have a perplexing problem.... protected void ArticleFormView_ItemUpdating(object sender, FormViewUpdateEventArgs e) { try { //Next line is line 36 if...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.