title: C# what am I doing wrong ? Exception thrown: 'System.FormatException' in mscorlib.dll line 90 and 231
body: <p>I keep getting this error when I try to run the debugger Exception thrown: 'System.FormatException' in mscorlib.dll<br>
  This is hypothetical reasons too here's my code it deals with predictions but whenever I try to run it I get the exception thrown, I had it working before but I don't know what happened but I've tried everything all of this is based off Jeff Heaton's books on prediction ML models </p>
  
  <pre><code> namespace PowerBallPredictor
  {
      using System;
      using System.Collections.Generic;
      using System.Net;
      using System.IO;
      using Encog.Neural.Networks;
      using Encog.ML.Data.Basic;
      using Encog.Neural.Networks.Layers;
      using Encog.Engine.Network.Activation;
      using Encog.Neural.Networks.Training.Propagation.Resilient;
      class Result
      {
          public int V1 { get; private set; }
          public int V2 { get; private set; }
          public int V3 { get; private set; }
          public int V4 { get; private set; }
          public int V5 { get; private set; }
          public int V6 { get; private set; }
          public Result(int v1, int v2, int v3, int v4, int v5, int v6)
          {
              V1 = v1;
              V2 = v2;
              V3 = v3;
              V4 = v4;
              V5 = v5;
              V6 = v6;
          }
          public Result(double[] values)
          {
              V1 = (int)Math.Round(values[0]);
              V2 = (int)Math.Round(values[1]);
              V3 = (int)Math.Round(values[2]);
              V4 = (int)Math.Round(values[3]);
              V5 = (int)Math.Round(values[4]);
              V6 = (int)Math.Round(values[5]);
          }
          public bool IsValid()
          {
              return
              V1 &gt;= 1 &amp;&amp; V1 &lt;= 69 &amp;&amp;
              V2 &gt;= 1 &amp;&amp; V2 &lt;= 69 &amp;&amp;
              V3 &gt;= 1 &amp;&amp; V3 &lt;= 69 &amp;&amp;
              V4 &gt;= 1 &amp;&amp; V4 &lt;= 69 &amp;&amp;
              V5 &gt;= 1 &amp;&amp; V5 &lt;= 69 &amp;&amp;
              V6 &gt;= 1 &amp;&amp; V6 &lt;= 69 &amp;&amp;
              V1 != V2 &amp;&amp;
              V1 != V3 &amp;&amp;
              V1 != V4 &amp;&amp;
              V1 != V5 &amp;&amp;
              V1 != V6 &amp;&amp;
              V2 != V3 &amp;&amp;
              V2 != V4 &amp;&amp;
              V2 != V5 &amp;&amp;
              V2 != V6 &amp;&amp;
              V3 != V4 &amp;&amp;
              V3 != V5 &amp;&amp;
              V3 != V6 &amp;&amp;
              V4 != V5 &amp;&amp;
              V4 != V6 &amp;&amp;
              V5 != V6;
          }
          public bool IsOut()
          {
              return
              !(
              V1 &gt;= 1 &amp;&amp; V1 &lt;= 69 &amp;&amp;
              V2 &gt;= 1 &amp;&amp; V2 &lt;= 69 &amp;&amp;
              V3 &gt;= 1 &amp;&amp; V3 &lt;= 69 &amp;&amp;
              V4 &gt;= 1 &amp;&amp; V4 &lt;= 69 &amp;&amp;
              V5 &gt;= 1 &amp;&amp; V5 &lt;= 69 &amp;&amp;
              V6 &gt;= 1 &amp;&amp; V6 &lt;= 69);
          }
          public override string ToString()
          {
              return string.Format(
              "{0},{1},{2},{3},{4},{5}",
              V1, V2, V3, V4, V5, V6);
          }
      }
      class ListResults : List&lt;Result&gt; { }
      class Program
      {
          static void Main(string[] args)
          {
              var fileDB = @"C:\Projects\Predictor\db\winnums-text.txt";
              try
              {
                  ListResults dbl = null;
                  if (CreateDatabases(fileDB, out dbl))
                  {
                      var deep = 27;
                      var network = new BasicNetwork();
                      network.AddLayer(
                      new BasicLayer(null, true, 6 * deep));
                      network.AddLayer(
                      new BasicLayer(
                      new ActivationSigmoid(), true, 5 * 6 * deep));
                      network.AddLayer(
                      new BasicLayer(
                      new ActivationSigmoid(), true, 5 * 6 * deep));
                      network.AddLayer(
                      new BasicLayer(
                      new ActivationLinear(), true, 6));
                      network.Structure.FinalizeStructure();
                      var learningInput = new double[deep][];
                      for (int i = 0; i &lt; deep; ++i)
                      {
                          learningInput[i] = new double[deep * 6];
                          for (int j = 0, k = 0; j &lt; deep; ++j)
                          {
                              var idx = 2 * deep - i - j;
                              var data = dbl[idx];
                              learningInput[i][k++] = (double)data.V1;
                              learningInput[i][k++] = (double)data.V2;
                              learningInput[i][k++] = (double)data.V3;
                              learningInput[i][k++] = (double)data.V4;
                              learningInput[i][k++] = (double)data.V5;
                              learningInput[i][k++] = (double)data.V6;
                          }
                      }
                      var learningOutput = new double[deep][];
                      for (int i = 0; i &lt; deep; ++i)
                      {
                          var idx = deep - 1 - i;
                          var data = dbl[idx];
                          learningOutput[i] = new double[6]
                          {
                              (double)data.V1,
                              (double)data.V2,
                              (double)data.V3,
                              (double)data.V4,
                              (double)data.V5,
                              (double)data.V6
                          };
                      }
                      var trainingSet = new BasicMLDataSet(
                      learningInput,
                      learningOutput
                      );
                      var train = new ResilientPropagation(
                      network, trainingSet);
                      train.NumThreads = Environment.ProcessorCount;
                  START:
                      network.Reset();
                  RETRY:
                      var step = 0;
                      do
                      {
                          train.Iteration();
                          Console.WriteLine("Train Error: {0}", train.Error);
                          ++step;
                      }
                      while (train.Error &gt; 0.001 &amp;&amp; step &lt; 20);
                      var passedCount = 0;
                      for (var i = 0; i &lt; deep; ++i)
                      {
                          var should =
                          new Result(learningOutput[i]);
                          var inputn = new BasicMLData(6 * deep);
                          Array.Copy(
                          learningInput[i],
                          inputn.Data,
                          inputn.Data.Length);
                          var comput =
                          new Result(
                          ((BasicMLData)network.
                          Compute(inputn)).Data);
                          var passed = should.ToString() == comput.ToString();
                          if (passed)
                          {
                              Console.ForegroundColor = ConsoleColor.Green;
                              ++passedCount;
                          }
                          else
                          {
                              Console.ForegroundColor = ConsoleColor.Red;
                          }
                          Console.WriteLine("{0} {1} {2} {3}",
                          should.ToString().PadLeft(17, ' '),
                          passed ? "==" : "!=",
                          comput.ToString().PadRight(17, ' '),
                          passed ? "PASS" : "FAIL");
                          Console.ResetColor();
                      }
                      var input = new BasicMLData(6 * deep);
                      for (int i = 0, k = 0; i &lt; deep; ++i)
                      {
                          var idx = deep - 1 - i;
                          var data = dbl[idx];
                          input.Data[k++] = (double)data.V1;
                          input.Data[k++] = (double)data.V2;
                          input.Data[k++] = (double)data.V3;
                          input.Data[k++] = (double)data.V4;
                          input.Data[k++] = (double)data.V5;
                          input.Data[k++] = (double)data.V6;
                      }
                      var perfect = dbl[0];
                      var predict = new Result(
                      ((BasicMLData)network.Compute(input)).Data);
                      Console.ForegroundColor = ConsoleColor.Yellow;
                      Console.WriteLine("Predict: {0}", predict);
                      Console.ResetColor();
                      if (predict.IsOut())
                          goto START;
                      if ((double)passedCount &lt; (deep * (double)3 / (double)10) ||
                          !predict.IsValid())
                          goto RETRY;
                      Console.WriteLine("Press any key for close...");
                      Console.ReadKey(true);
                  }
              }
              catch (Exception exception)
              {
                  Console.WriteLine(exception.ToString());
              }
          }
          static bool CreateDatabases(
          string fileDB,
          out ListResults dbl)
          {
              dbl = new ListResults();
              using (var reader = File.OpenText(fileDB))
              {
                  var line = string.Empty;
                  var separator = new string[] { "  " };
                  while ((line = reader.ReadLine()) != null)
                  {
                      if (line == "Draw Date   WB1 WB2 WB3 WB4 WB5 PB  PP") continue;
                      var values = line.Split(separator, StringSplitOptions.None);
                      var res = new Result(
                      int.Parse(values[1]),
                      int.Parse(values[2]),
                      int.Parse(values[3]),
                      int.Parse(values[4]),
                      int.Parse(values[5]),
                      int.Parse(values[6])
                      );
                      dbl.Add(res);
                  }
              }
              return true;
          }
      }
  </code></pre>
  
  <p>and this is what the output is </p>
  
  <pre><code>'PowerBallPredictor.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'. 
  'PowerBallPredictor.exe' (CLR v4.0.30319: DefaultDomain): Loaded 'C:\Projects\Predictor\PowerBallPredictor\PowerBallPredictor\bin\Debug\PowerBallPredictor.exe'. Symbols loaded.
  'PowerBallPredictor.exe' (CLR v4.0.30319: PowerBallPredictor.exe): Loaded 'C:\Projects\Predictor\PowerBallPredictor\PowerBallPredictor\bin\Debug\encog-core-cs.dll'. 
  Exception thrown: 'System.FormatException' in mscorlib.dll
  'PowerBallPredictor.exe' (CLR v4.0.30319: PowerBallPredictor.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'. 
  'PowerBallPredictor.exe' (CLR v4.0.30319: PowerBallPredictor.exe): Loaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'. 
  The program '[6968] PowerBallPredictor.exe' has exited with code 0 (0x0).
  </code></pre>