Loop N1* could not be added because it could not be found in the specification for ST

Oct 17, 2013 at 6:18 PM
When trying to create an 834 from scratch, I get this exception when trying to add an N1 loop.
OopFactory.X12.Parsing.Model.TransactionValidationException was unhandled
  HResult=-2147024809
  Message=Loop N1* could not be added because it could not be found in the specification for ST
  Source=OopFactory.X12
  ElementId=ST
  Value=N1*
  StackTrace:
       at OopFactory.X12.Parsing.Model.LoopContainer.AddLoop[T](T loop)
       at TestEdi834.Program.TestMapDataToFile() in c:\_Projects\Test\TestEdi834\TestEdi834\Program.cs:line 84
       at TestEdi834.Program.Main(String[] args) in c:\_Projects\Test\TestEdi834\TestEdi834\Program.cs:line 16
       at System.AppDomain._nExecuteAssembly(RuntimeAssembly assembly, String[] args)
       at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
       at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
       at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
       at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
       at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
       at System.Threading.ThreadHelper.ThreadStart()
  InnerException: 
I'm fairly new to this EDI stuff, so I may just be doing something entirely wrong. If so, any help would be appreciated. Thank you.
Coordinator
Oct 17, 2013 at 7:08 PM
The default 834 specification embedded in the assembly requires that you have an entity code identifier of "P5", "IN", "BO" or "TV". This is an implementation of the 834. It will be able to find the appropriate spec for your N1 loop once you have supplied an entity code identifier. If you are looking to use a different entity code you may need to use a more generic 834 specification that you inject yourself.

See here for the currently embedded 834: https://x12parser.codeplex.com/SourceControl/latest#trunk/src/OopFactory.X12/Specifications/Ansi-834-5010Specification.xml.

See here to inject your own: https://x12parser.codeplex.com/wikipage?title=Injecting%20your%20own%20X12%20Specification

Examples of how to add an N1 loop are here: https://x12parser.codeplex.com/SourceControl/latest#trunk/tests/OopFactory.X12.Tests.Unit/Creation/Invoice810CreationTester.cs

Feel free to post your code that adds the N1 loop and I will take a look.

It might be that I need to modify the TypedLoopN1 so that you can pass in the entity identifier code before it gets attached to the transaction.
Oct 17, 2013 at 7:42 PM
Edited Oct 17, 2013 at 7:45 PM
The entity code identifier that I'm using is "P5", but I wasn't setting that until after adding the loop to the transaction, i.e.:
var sponsorLoop = transaction.AddLoop(new TypedLoopN1());
sponsorLoop.N101_EntityIdentifierCode = "P5";
sponsorLoop.N102_Name = "John Smith";
sponsorLoop.N103_IdentificationCodeQualifier = "FI";
sponsorLoop.N104_IdentificationCode = "001234567";
The exception occurs on the AddLoop line, so there is no chance to set the EntityIdentifierCode before the exception happens. After seeing your post, I tried setting that field at the time that the loop was instantiated (before adding it to the transaction like so:
var sponsorLoop = transaction.AddLoop(new TypedLoopN1()
{
    N101_EntityIdentifierCode = "P5"
});
//sponsorLoop.N101_EntityIdentifierCode = "P5";
sponsorLoop.N102_Name = "John Smith";
sponsorLoop.N103_IdentificationCodeQualifier = "FI";
sponsorLoop.N104_IdentificationCode = "001234567";
but this resulted in a NullReferenceException on the AddLoop line.
Oct 17, 2013 at 7:51 PM
I noticed that when examining the transactions at runtime that the specification for the 810, used in the example from the unit test, has N1 included in the LoopSpecifications property, but the 834 transaction does not include this.
Coordinator
Oct 17, 2013 at 7:55 PM
The 810 example worked because there were not multiple N1 loops defined at the same level. This is one way to fix it by having a generic spec that doesn't differentiate between the different implementations of N1.

I think what I need to do is make TypedLoopN1 more like TypedLoopNM1 so that you can pass in the code and it can be available when it attaches to the transaction and tries to resolve which loop spec to use. I can try and get the code checked by tomorrow for you to try.
Oct 17, 2013 at 7:58 PM
Edited Oct 17, 2013 at 8:20 PM
Thank you. I appreciate the help.
Oct 21, 2013 at 4:52 PM
Would it be enough to override GetSegmentString and Initialize in TypedLoopN1 as it is done in TypedLoopNM1? That is the only major difference I can see between those two classes, but I don't know enough about the code base to understand if that will cause any problems.

I'm going to try it today and I'll report back my findings here.
Nov 13, 2013 at 3:31 PM
I created an issue here and submitted patch 15428 to fix this. Sorry for the delay in submitting a patch.