NumberFormat problem in StreamWriter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • schaf

    NumberFormat problem in StreamWriter

    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 ?

  • ssamuel

    #2
    Re: NumberFormat problem in StreamWriter

    You probably want to create your own XML serialization by implementing
    IXmlSerializabl e. DateTime.ToStri ng(string) will give you the same
    string regardless of culture if you want it to. Bear in mind that
    culture and internationaliz ation 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.ToStri ng("yyyyMMddHHm mss.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



    schaf wrote:
    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 ?

    Comment

    Working...