Parse(System.IO.Stream)' is obsolete

Jan 28, 2014 at 10:33 PM
Following code giving warning as obsolete, i tried using ParseMultiple but end up with error. How to use it?
FileStream fStream = new FileStream(@"C:\EDItoXML\h837.txt",FileMode.Open,FileAccess.Read);
            Stream outputFile = new FileStream(@"C:\EDItoXML\h837_TestLog.txt", FileMode.Create, FileAccess.Write);
                                            
            X12Parser parser = new X12Parser();
                        
            Interchange interchange = parser.Parse(fStream);
            string xmlfile = interchange.Serialize();
Warning 57 'OopFactory.X12.Parsing.X12Parser.Parse(System.IO.Stream)' is obsolete: 'Use ParseMultiple instead. Parse will only return the first interchange in the file.' (CS0618) TestUserCode.cs

"Error 57 Cannot implicitly convert type 'System.Collections.Generic.List<OopFactory.X12.Parsing.Model.Interchange>' to 'OopFactory.X12.Parsing.Model.Interchange' (CS0029) TestUserCode.cs
"
Developer
Jan 29, 2014 at 3:23 PM
Parse multiple is going to return a List<Interchange> not just a single entity Interchange. You need to change your above code to:
FileStream fStream = new FileStream(@"C:\EDItoXML\h837.txt",FileMode.Open,FileAccess.Read);
            Stream outputFile = new FileStream(@"C:\EDItoXML\h837_TestLog.txt", FileMode.Create, FileAccess.Write);
                                            
            X12Parser parser = new X12Parser();
                        
            List<Interchange> interchange = parser.ParseMultiple(fStream);
            string xmlfile = interchange.Serialize();
Jan 29, 2014 at 10:22 PM
Edited Jan 29, 2014 at 10:30 PM
Thank you Mark, it helps; however i am getting error while accessing the Transaction segment. Please help.
                 FileStream fStream = new FileStream(@"C:\EDItoXML\270.txt",FileMode.Open,FileAccess.Read);
            X12Parser parser = new X12Parser();
            
            List<Interchange> interchange = parser.ParseMultiple(fStream);
            
            Transaction transaction = interchange[0].FunctionGroups.First().Transactions.First();
Error 195 'System.Collections.Generic.IEnumerable<OopFactory.X12.Parsing.Model.FunctionGroup>' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IEnumerable<OopFactory.X12.Parsing.Model.FunctionGroup>' could be found (are you missing a using directive or an assembly reference?) (CS1061) TestUserCode.cs
Developer
Jan 30, 2014 at 3:40 PM
If I am understanding right what you are trying to do - get the first transaction in the interchange, you could try this:

FileStream fStream = new FileStream(@"C:\EDItoXML\270.txt",FileMode.Open,FileAccess.Read);
            X12Parser parser = new X12Parser();
            
            List<Interchange> interchanges = parser.ParseMultiple(fStream); //I would suggest pluralizing interchange
            
            Transaction transaction =interchanges.First().FunctionGroups.First().Transactions.First();
            
            //Or something like this if you have need of it...
            foreach (Interchange interchange   in interchanges)
                        {
                            foreach (FunctionGroup group in interchange.FunctionGroups)
                            {
                                foreach (Transaction transaction in group.Transactions)
                                {
                                    var loops = transaction.Loops;
                                    //And so on....
                                    
                                }
                                
                            }
                            
                        }
Marked as answer by MarkWalls on 2/19/2014 at 8:59 AM
Jan 31, 2014 at 8:05 PM
Hi Mark, the looping helps however the ParserMultiple still giving me the same error.Actually, I am trying to edit an 837 file in HI (BK & BF) segment by replacing ICD9 codes with corresponding ICD10 codes . Would you please guide?
Feb 11, 2014 at 9:54 PM
Hi Mark, I get it worked. Thank you for your help.