R
Robin Tucker
(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
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