My application doesn't load levels properly on computers with different cultures.
If I change the Thread culture to InvariantCulture I can reproduce the issue on my computer
I think it is failing at reading XML information, some assets seem to get loaded in that by coincidence don't break the culture.
I'm using a StreamReader, XmlDocument and XmlNode, I've tried formatting to InvariantCulture but to no avail.
I don't get any error messages, it seems to load and start the game properly but many tiles are missing.
Has anyone come across the same issue and figured out a solution?
This seems to be a very similar issue, although I'm not getting any exceptions since I'm not using fonts;
foreign culture XML text parsing
By defining the culture of the thread myself, in this case forcing it to be Swedish on all computers the issue was solved.
Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("sv-SE");
Related
I have a C# forms application. As a part of its functionality, it writes double values to a file in string format, some of which are double.Infinity.
There is another part of application that reads these values from file and converts them back to double.
When writing values part is performed on windows 7 and reading the same file is performed on Windows 10, then there is format exception while converting 'infinity'. It appears the symbol used by the default (us-en) culture changed between Windows 8 and 10.
There are many instances of Convert.ToDouble() in application and handling each of these instances through try-catch or by using double.tryParse() isn't a feasible solution as it will require changes in many projects.
Is there any workaround for this to avoid this format exception problem?
Thanks in advance,
Kapil
This is an even bigger issue when dealing with databases and storing data in other cultures too. We initially had a problem in that the Spanish version of our software wouldn't read infinity properly, and would store infinity as the symbol, instead of the word. Even when trying to force it onto the english culture, it appeared broken.
We then saw this issue crop up on Windows 10 in the english culture, where the infinity symbol would now be saved in the database. This issue has the potential to cause problems across Windows versions and across cultures.
The safest thing to do is store and retrieve data, whether in a file or a database, using CultureInfo.InvariantCulture. This way it will always be as you expect it.
If you already have a problem in files/database, then you could run a fairly simple script to seek out the 'Double|∞' and replace it with 'Double|Infinity' which is the invariant type.
This will save you from future problems
One of our clients requested that some terminology we're using should be changed according to their needs. That means changing a bunch of labels in forms and user messages. Our application is developed as multi-language application so everything is in resource files.
To solve this need I've decided to create a custom culture. I have created hr-HR-HP from standard hr-HR language. I did some tests and everything worked fine.
However, in our project, our third party components break down with the following exception
CultureNotFoundException: Culture is not supported.
Parameter name: culture
4096 (0x1000) is an invalid culture identifier.
Google says that this happens when CultureInfo is created via LCID and that is not supported for custom cultures. So, to avoid this i set Culture parameters as follows:
Thread.CurrentThread.CurrentCulture = new CultureInfo("hr-HR");
Thread.CurrentThread.CurrentUICulture = new CultureInfo("hr-HR-HP");
Great, the error is gone and forms read their resources as expected. However, now ResourceManager is the problem. It's using hr satellite assembly instead of hr-HR-HP one. I use ResourceManager to read the user messages from satellite assemblies.
Any suggestions? Is it possible to specify which language I want for ResourceManager? Should I try some other approach?
Silly me, I was so close to the answer. Just a little more googling reveals that I can specify what culture I want in ResourceManager.GetString() method.
I wonder if someone can help me.
I have an application that uses a config file to store window locations, when I store the location I get it as a Rect and do a simple ConfigSection.SetValue("Location", value.ToString());
99% of the time this string is written as comma separated values x,y,w,h however recently a user complained that our app was raising an exception when opening
After following it through I found that an invalid format exception was raised when parsing a window location, I looked into the config file the location had been written as x;y;w;h, using semicolon as the separator.
I looked at the regional settings and found List Separator, but when I try changing this to a semicolon (as an attempt to replicate the issue), the rect string is still written as comma separated. This means I am unable to replicate locally and do not really know what has caused the issue.
Any insight as to how the separator may have changed would be much appreciated.
Thanks
Kieran
Use InvariantCulture in:
ConfigSection.SetValue("Location", value.ToString(CultureInfo.InvariantCulture));
In the namespace System.Globalization.
Then, the format of the string will use a "generic" culture that is exactly the same on all computers (and does not depend on the settings of the computer).
I have a very tricky question here. I've been benging my head on this issue for several hours with no success.
I am building an application to be deployed on numerous machines, with different cultures.
As a precautionary I decided to use the Culture class to help convert between string to dates.
I noticed that when I change my windows operation system date from :
10/07/2011 to 10-07-2011
The CurrentCulture doesn't get updated, I keep seeing the dates as 10/07/2011.
Why is that? Is there any workaround?
You need to change the Culture in the IIS environment (or better in Web.config) and not in the OS.
that way you'll Guarantee that all the machines will work on the same Culture.
try to add the following line to your web.config:
<globalization culture="he-IL" enableClientBasedCulture="false" uiCulture="he-IL" />
just change the he-IL to your proffered culture
It works correctly for me, but only after I restart my application. I assume the current culture is loaded at the start of the application and cached, so, for the change to take effect, you have to restart the application.
A long as the value can still be interpreted as a date, it will always be formatted to your CurrentCulture. This is by design.
You need to explicitly change CurrentCulture, so data shows (or is converted) to a new format. Look at CurrentCulture as how data is going to be displayed on your end.
I've got a German VisualStudio 9.0. Working with doubles and doing quite some parsing, I came into trouble because of the decimal separator.
What I'm looking for is a way to either switch the whole IDE (and therefore all the projects created with it) to "en-gb" or do it project wide. I chose en-gb because of the lack of am's and pm's which I don't need.
I tried to set it by using Thread.CurrentThread.CurrentCulture, but this regards only the one thread. Then I found the Application wide setting, which seems to be not what I'm looking for when developing console applications.
Any idea? Thank you for reading.
The culture of the application defaults to the culture of the machine it's running on, not the machine it was developed on. The IDE is irrelevant here.
If you need to parse/format values using a specific culture, I suggest you do that explicitly - changing the current culture of all threads would be incorrect in almost all settings, IMO.