none
Issue to file RRS feed

  • Question

  • Hi,

    Which invalid character within fileis leading to issue below?

    Data at offset 0 ('ÿþ0<NULL>0<NULL>:<NULL>I<NULL>F<NULL>T<NULL>M<NULL>...') does not match INITIATOR '00'

      of TYPE X'0005' (00_Header Segment IFTMBFMIN EDI).


    Many Thanks & Best Regards, Hua Min


    Wednesday, June 3, 2020 9:55 AM

Answers

  • What is the SteamWriter for?

    Btw, if you set a breakpoint to read the string returned by StreamReader, there should be no <null> character now.

    If the error you quoted is from another EDI program that reads the file which StreamWriter is emitting, that means that EDI program is probably expecting Encoding.ASCII or UTF8 (Both encoding is the same at lower ASCII range).


    Thursday, June 4, 2020 6:02 AM
    Answerer

All replies

  • Nothing to download there, check to see if permission is set correctly.

    That said, judge from output you shown, possibly you've not read the file with correct Encoding.

    Wednesday, June 3, 2020 11:30 AM
    Answerer
  • It appears that the file contains a unicode BOM (byte order marker)  -- 0xFFFE

    The BOM indicates the file is encoded as UTF-16LE (little endian).

    • Edited by RLWA32 Wednesday, June 3, 2020 11:51 AM
    Wednesday, June 3, 2020 11:47 AM
  • Hi,

    Thanks to all.

    Can you see if you can read this file

    I am not sure which is invalid character to such file.


    Many Thanks & Best Regards, Hua Min


    Wednesday, June 3, 2020 1:35 PM
  • I just loaded your file and displayed it in a RichTextBox without problem :

    Wednesday, June 3, 2020 1:58 PM
  • Agree with RLWA32, Checked that file is written in UTF16LE encoding.

    Just pass System.Text.Encoding.Unicode to the second parameter of StreamReader to read it.

    Thursday, June 4, 2020 1:14 AM
    Answerer
  • Thanks to all.
    Originally I used Encoding.Unicode (as 2nd parameter to StreamReader, and 3rd parameter to StreamWriter), as I am inserting a CR to each line.

    I changed it to System.Text.Encoding.Unicode but details in the file is wrong. 

    I think option Unicode is reason of problem. What to adjust?


    Many Thanks & Best Regards, Hua Min



    Thursday, June 4, 2020 2:24 AM
  • I can read it without problem using the following code:

            static void Read()
            {
                const string Filename = "CNMBF_CNSNHEPI_20200602120556_758B.edi";
                string content;
                using (StreamReader sr = new StreamReader(Filename, true))
                {
                    while (!sr.EndOfStream)
                    {
                        content = sr.ReadLine();
                        Console.WriteLine(content);
                    }
                }
            }

    And the output for first 2 lines are:

    00:IFTMBF:BOOKING:9:75036097X:PPP_CNSNHEPI:202006021206'
    02:EUNBSE200600352:PPPUJAN9599115:CY-CY:EUMEX LINE (NIJANO) LIMITED:PPP:::::::::
    :PPPJAN2018::'

    Are you coding for .NET Core running on non-x86 CPUs? If that's the cause the architectural endianness may cause the text not be read correctly. Since this file have Byte-Order-Mark supplied you may change the second parameter to true and let the StreamReader decide what is best for you.

    Thursday, June 4, 2020 4:21 AM
    Answerer
  • Hi,
    I have these
                        using (StreamReader sr = new StreamReader(@fileName, true))
                        ...
                                using (StreamWriter sw = new StreamWriter(@d0, true, System.Text.Encoding.Unicode))
    


    but there is still problem.

    Many Thanks & Best Regards, Hua Min

    Thursday, June 4, 2020 4:38 AM
  • What is the SteamWriter for?

    Btw, if you set a breakpoint to read the string returned by StreamReader, there should be no <null> character now.

    If the error you quoted is from another EDI program that reads the file which StreamWriter is emitting, that means that EDI program is probably expecting Encoding.ASCII or UTF8 (Both encoding is the same at lower ASCII range).


    Thursday, June 4, 2020 6:02 AM
    Answerer