title: BIML SSIS ScriptTask as a data source - Error with OutputBuffer
body: <p>I am getting the below error when trying to generate a package through BIML using a ScriptTask as a datasource.  I have a large (circa 5GB) XML file to load and wanted to use a StreamReader to get the data into the database.  </p>
  
  <blockquote>
    <p>'Output0Buffer' does not contain a definition for 'PORTF_LIST' and no extension method 'PORTF_LIST' accepting a first argument of type 'Output0Buffer' could be found (are you missing a using directive or an assembly reference?). </p>
  </blockquote>
  
  <p>This is occurring for each column. The columns are dynamic and come from a separate method in a c# class looking at the dacpac so should be the same names and casing everywhere.</p>
  
  <p>Sample of the file as below:</p>
  
  <pre><code>&lt;ANALYTICS&gt;
    &lt;INSTRUMENTS ASOF_DATE="3/31/2017" CREATE_DATE="4/2/2017" RECORDS="3763"&gt;
      &lt;INSTRUMENT&gt;
        &lt;PORTF_LIST&gt;XX1245897&lt;/PORTF_LIST&gt;
        &lt;PRT_FULL_NAME&gt;Convertible Bonds&lt;/PRT_FULL_NAME&gt;
        &lt;ISIN&gt;11803384&lt;/ISIN&gt;
      &lt;/INSTRUMENT&gt;
       &lt;/INSTRUMENTS&gt;
  &lt;/ANALYTICS&gt;
  </code></pre>
  
  <p>Output buffer is defined as below (there are 250 odd columns, but all follow the same pattern:</p>
  
  <pre><code>           &lt;OutputBuffers&gt;
                  &lt;OutputBuffer Name="Output0" IsSynchronous="false"&gt;
                      &lt;Columns&gt;
  &lt;Column Name="PORTF_LIST" DataType="String" Length="255"/&gt;
  &lt;Column Name="PRT_FULL_NAME" DataType="String" Length="255"/&gt;
  &lt;Column Name="ISIN" DataType="String" Length="255"/&gt;
                      &lt;/Columns&gt;                    
                  &lt;/OutputBuffer&gt;                                 
              &lt;/OutputBuffers&gt;   
  </code></pre>
  
  <p>The script task code where I am trying to add to the buffer is below:</p>
  
  <pre><code>    &lt;#@ property name="Elements" type="String" #&gt;  
      &lt;#@ property name="Columns" type="String" #&gt;  
      &lt;#@ property name="BufferColumns" type="String" #&gt;  
      &lt;#@ property name="RootElement" type="String" #&gt;  
      &lt;ScriptComponentProject ProjectCoreName="SC_eb1debcd2374468ebccbbfad4fbe5976" Name="XmlSource"&gt;
                &lt;AssemblyReferences&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSPipelineWrap" /&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.DTSRuntimeWrap" /&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.PipelineHost" /&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.TxScript" /&gt;                  
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.ManagedDTS.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="Microsoft.SqlServer.ScriptTask.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.AddIn.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Data.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Windows.Forms.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Xml.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Xml.Linq.dll" /&gt;
                  &lt;AssemblyReference AssemblyPath="System.Core.dll" /&gt;
               &lt;/AssemblyReferences&gt;
              &lt;OutputBuffers&gt;
                  &lt;!--    
                  Define what your buffer is called and what it looks like
                  Must set IsSynchronous as false. Otherwise it is a transformation
                  (one row enters, one row leaves) and not a source.
                  --&gt;
                  &lt;OutputBuffer Name="Output0" IsSynchronous="false"&gt;
                      &lt;Columns&gt;
                          &lt;#=BufferColumns#&gt;
                      &lt;/Columns&gt;                    
                  &lt;/OutputBuffer&gt;                                 
              &lt;/OutputBuffers&gt;              
                &lt;Files&gt;
                  &lt;File Path="Properties\AssemblyInfo.cs"&gt;
  using System.Reflection;
  using System.Runtime.CompilerServices;
  [assembly: AssemblyTitle("XmlSource")]
  [assembly: AssemblyDescription("Script Component as source")]
  [assembly: AssemblyConfiguration("")]
  [assembly: AssemblyCompany("")]
  [assembly: AssemblyProduct("XmlSource")]
  [assembly: AssemblyCopyright("Copyright @ 2017")]
  [assembly: AssemblyTrademark("")]
  [assembly: AssemblyCulture("")]
  [assembly: AssemblyVersion("1.0.*")]
  &lt;/File&gt;
  &lt;File Path="main.cs"&gt;
  &lt;![CDATA[
  
  using System;
  using System.Data;
  using Microsoft.SqlServer.Dts.Pipeline.Wrapper;
  using Microsoft.SqlServer.Dts.Runtime.Wrapper;
  using System.Security;
  using System.Collections.Generic;
  using System.IO;
  using System.Linq;
  using System.Text;
  using System.Xml;
  using System.Xml.Linq;
  using System.Windows.Forms;
  
  [Microsoft.SqlServer.Dts.Pipeline.SSISScriptComponentEntryPointAttribute]
  public class ScriptMain : UserComponent
  {
  
          public override void PreExecute()
          {
              base.PreExecute();
  
          }
  
          public override void PostExecute()
          {
              base.PostExecute();
          }
  
          public string sourceFile =  Dts.Variables["User::FileName"].Value.ToString();
  
          public override void CreateNewOutputRows()
          {
              foreach (var myXmlData in (
                     from elements in StreamReader(sourceFile, "INSTRUMENT")
                     select new 
                          {
  PORTF_LIST = elements.Element("PORTF_LIST").Value,
  PRT_FULL_NAME = elements.Element("PRT_FULL_NAME").Value,
  ISIN = elements.Element("ISIN").Value
  
                          }
                  ))
                  {
                      try
                      {
                          Output0Buffer.AddRow();
      Output0Buffer.PORTF_LIST = myXmlData.PORTF_LIST;
      Output0Buffer.PRT_FULL_NAME = myXmlData.PRT_FULL_NAME;
      Output0Buffer.ISIN = myXmlData.ISIN;
                      }
                      catch (Exception e)
                      {
                          string errorMessage = string.Format("Data retrieval failed: {0}", e.Message);
                          bool cancel;
                          ComponentMetaData.FireError(0, ComponentMetaData.Name, errorMessage,string.Empty,0, out cancel);
                      }
  
                  }
  
  
          }
  
  
          public static IEnumerable&lt;XElement&gt; StreamReader(String filename, string elementName)
          {
  
                           // Create an XML reader for this file.
                          using (XmlReader reader = XmlReader.Create(filename))
                          {
                              reader.MoveToContent(); // will not advance reader if already on a content node; if successful, ReadState is Interactive
                              reader.Read();          // this is needed, even with MoveToContent and ReadState.Interactive
                              while(!reader.EOF &amp;&amp; reader.ReadState == ReadState.Interactive)
                              {
                                  if(reader.NodeType == XmlNodeType.Element &amp;&amp; reader.Name.Equals(elementName))
                                  {
                                       // this advances the reader...so it's either XNode.ReadFrom() or reader.Read(), but not both
                                       var matchedElement = XNode.ReadFrom(reader) as XElement;
                                       if(matchedElement != null)
                                           yield return matchedElement;
                                  }
                                  else
                                      reader.Read();
                              }
                              reader.Close();
  
                          }
          }
  
  }
  ]]&gt;
                  &lt;/File&gt;
                &lt;/Files&gt;
                &lt;ReadOnlyVariables&gt;
                    &lt;Variable Namespace="User" DataType="String" VariableName="FileName" /&gt;
                &lt;/ReadOnlyVariables&gt;
                &lt;ReadWriteVariables&gt;
                &lt;/ReadWriteVariables&gt;
              &lt;/ScriptComponentProject&gt;
  </code></pre>
  
  <p>I've checked the code in a console app and it reads the XML file fine, but no luck with the BIML. There are about 250 odd columns so I am trying to avoid doing this manually so if you have any ideas what I am doing wrong I'd really appreciate it!</p>