NumberFormat problem in StreamWriter

  • Thread starter Thread starter schaf
  • Start date Start date
S

schaf

Hi NG!
I have a .NET project which uses a sublibrary written in C++.
On the .NET side I use the XMLSerializer to serialize an object (into
an MemoryStream). This stream would be casted into a byte-array and
then passed to the C++ sublibrary.
The sublibrary ha sthe intention to convert the XML into and other XML
based format.

Unfortunately the values in the final file are wrong in the following
case.
If the workstation is running with loc-setting en-US (numberFormat)
everything works without problem, but if I change the NumberFormat to
fr-FR the results are wrong.

I compared the XML before passing it to the C++ library. There is no
difference between the two files (fr or us). All double values were
written with a point (no comma in french is used). Therefore I guess
the XMLSerializer writes the file independent of the LOC settings ?!

I tried to start a separate thread for calling the C++ function. I
changed the ThreadCulture, but nothing changed.

I can't change the CultureInfo of the StreamWriter (it's a getter
property)! how can I solve my problem ?
 
You probably want to create your own XML serialization by implementing
IXmlSerializable. DateTime.ToString(string) will give you the same
string regardless of culture if you want it to. Bear in mind that
culture and internationalization is a paradigm that *only* applies to
UIs, not to the internal workings of an object. You should always store
and transmit your data in an invariant format, and let the culture
thing take over when you need to show it to a user.

Try something like:

string myDate = DateTime.ToString("yyyyMMddHHmmss.fff");

which will give you a string containing something like

20061116104401.273

(This is incidentally expressable as a decimal, or a long if you drop
the decimal point.) I don't know what your C++ library expects, but
changing the format string will give you something that it expects.


Stephan
 
Back
Top