0

Using code like:

...
EdiMessage ediMessage = (EdiMessage)instance;
using (FileStream ediStream = File.OpenWrite(file))
{
    using (EdifactWriter writer = new EdifactWriter(ediStream))
    {
       writer.Write(ediMessage);
    }
}

I receive an error message 'No interchange was started.'

Stack trace below the writer.Write call (last public version of Edifabric):

at EdiFabric.Framework.Writers.EdiWriter`2.Write(EdiMessage message)

It concerns a D96A INVOIC object with BGM, some FTX and a UNH. The object class is . And the exception is raised by EdiWriter on the call writer.Write.

The ediMessage contents seem valid. According to Edifabric documentation it should add the default EDIFACT separators automatically:

If not explicitly specified the writer will use the default separators per standard:

What did I forget to setup?

Guido Leenders
  • 4,232
  • 1
  • 23
  • 43
  • The message 'No interchange was started.' means that no interchange header segment was created. EDI documents follow a structure such as: Interchange header->Group header (optional for EDIFACT)->Transaction->Group trailer->Interchange trailer. In your case you need to Write a UNB first and then Write all the transactions\messages. – Don Zoeggerle Sep 13 '17 at 08:00
  • @DonZoeggerle thanks for background; the word "Interchange" in the error was due to lack of EDIFACT terms not clear to me then. With some extra gray cells, I now know it refers to an EDI message interchange. EDIFACT works great; simple, elegant design! – Guido Leenders Sep 13 '17 at 09:00

1 Answers1

0

It seems a documentation bug; the defaulting does not happen. When changing the code to:

using (EdifactWriter writer = new EdifactWriter(ediStream))
{
  var unb = new UNB(); // Begin interchange.
  writer.Write(unb, Separators.Edifact);

  writer.Write(ediMessage);
}

the unb inserts a header in the document after which in this case one message is added. The code now raised an "Object reference not set to an instance of an object." with call stack

at EdiFabric.Core.Model.Edi.EdiMessage.GetControlNumber(String tag, Int32 position)

which was fixed by adding:

ediMessage.ControlNumber = ...;
Guido Leenders
  • 4,232
  • 1
  • 23
  • 43