Can't read message - Could not load file or assembly

When I try to read my EDI file I get the following error:

"Could not load file or assembly 'AssemblyName' or one of its dependencies. The system cannot find the file specified."

How to resolve it?

The error message means that there is no reference to the aforementioned assembly. The assembly name is specified in the reader constructor like this:

 using (var ediReader = new X12Reader(ediStream, "AssemblyName"))

Internally the parser uses Assembly.Load(AssemblyName) where the assembly name can be found in the project references.

For example - to read EDI files, according to EDI templates that are compiled as part of a project named "EdiFabric.Sdk.X12.Templates.V004010" with assembly name:

you need to:

  • Add a reference to that project 

  • Use the exact assembly name in the reader constructor
 var ediReader = new X12Reader(ediStream, "EdiFabric.Sdk.X12.Templates.V004010")
Writer adds extra three binary characters at the beginning of my file

When writing directly to a file sometimes you may unexpectedly get 3 extra characters written at the beginning of the file:

0xef, 0xbb, and 0xbf

How to prevent it from happening?

This is due to the encoding. By default, the writer uses UTF8 and initializes it with Encoding.UTF8 which a UTF8Encoding object that provides a Unicode byte order mark (BOM).

To instantiate a writer that doesn't provide a BOM, call it with an overload of the UTF8Encoding constructor:

var writer = new X12Writer(customFilename, 
new X12WriterSettings { Encoding = new UTF8Encoding() });
Why do I get ReaderErrorContext?

The ReaderErrorContext is an IEdiItem which is returned in one of the following situations:

Was this article helpful?
2 out of 2 found this helpful