title: Dynamics AX 2009: Batch Trouble with AsciiIO class
body: <p>I have a custom class, we'll call it FileProcessUpload and it extends RunBaseBatch. It more or less creates a CSV file and then uploads it to an FTP server. When the class is run manually, everything works fine. However, when submitted as a Batch Job, there is an error in the infolog stating "AsciiIO object not initialized".</p>
  
  <p>Probably the most important thing to note here is that this Batch Job is being delegated to a different AOS.</p>
  
  <p>Here is a cropped down version of the offending code:</p>
  
  <pre><code>void CreateFiles()
  {
      #File
      AsciiIO             asciiio;
      FileIOPermission    permission;
      ATable              aTable;
      str                 outputFile;
      str                 directory;
      ;
      directory       = @'C:\Uploads';
      ouptutFile      = directory + @'\output.csv';
  
      if (!WinAPI::folderExists(directory))
      {
          WinAPI::createDirectory(directory);
      }
  
      // Try to assert the appropriate file access mode
      permission = new FileIOPermission(outputFile, #io_write);
      permission.assert();
  
      // Try to open the file for writing
      asciiio = new AsciiIO(outputFile, #io_write);
      if (asciiio != null)
      {
          while select aTable
          {
              // Write the necessary lines into the file
              asciiio.write(aTable.field1 + ',' + aTable.field2);
          }
      }
      else
      {
          error('Could not create file: ' + outputFile);
      }
      // Close file and release permission assertion
      asciiio = null;
      CodeAccessPermission::revertAssert();
  
  }
  </code></pre>