title: Visual Studio C# not identifying closing braces
body: <p>I'm working with Visual Studio, making a .CSHTML web page.
  The code was working code. Through some unknown edit? or bug?(unlikely)
  Visual studio will not recognize the last set of {}.
   The ones that start with 
  @{ C# code here</p>
  
  <p>}</p>
  
  <p>Compiler Error:
  "Parser Error Message: The code block is missing a closing "}" character.  Make sure you have a matching "}" character for all the "{" characters within this block, and that none of the "}" characters are being interpreted as markup.</p>
  
  <p>Source Error: </p>
  
  <p>Line 2:<br>
  Line 3:<br>
  Line 4:  @{
  Line 5:              var db = Database.Open("DevDbCS");
  Line 6:<br>
  "</p>
  
  <p>I have copy and pasted my code to notepad ++ that highlights the corresponding bracket if I select one. I have confirmed that all brakes open and close correctly. I even dropped it into Processing, (wont compile) but it says all good too. </p>
  
  <pre><code>@{
          var db = Database.Open("DevDbCS");
  
          var selectThorneID = "SELECT ThorneID, Status FROM Batch_Record WHERE Status = 'ACTIVE' ORDER BY ThorneID ASC";
  
          //Variables
          var ThorneID = " ";
          var frmInsertV = "";
          var frmInsert = "";
          var frmUpdate = "";
          var StartUnits = "";
          var EndUnits = "";
          var yield = "";
          var formValues = new double[29];//array for holding results from Query
          var QC = "";
          int RecordCount = 0;
  
          var sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast&lt;DynamicRecord&gt;().ToArray();
  
  
          if (IsPost)
          {
  
              switch (Request.Form["userInput"])
              {
                  case "Submit":
                      ThorneID = Request.Form["ThorneID"];
                      StartUnits = Request.Form["s12"];
                      EndUnits = Request.Form["s15"];
                      yield = Request.Form["s17"];
                      QC = Request.Form["QC"];
  
                      //Set to zero to avoid trying to put nulls in DB
                      if (Request.Form["s12"] == null)
                      {
                          StartUnits = "0";
                      }
                      else
                      {
                          StartUnits = Request.Form["s12"];
                      }
  
                      if (Request.Form["s15"] == null)
                      {
                          EndUnits = "0";
                      }
                      else
                      {
                          EndUnits = Request.Form["s15"];
                      }
  
                      if (Request.Form["s17"] == null)
                      {
                          yield = "0";
                      }
                      else {
                          yield = Request.Form["s17"];
                      }
  
                      for (int i = 1; i &lt;= 26; i++)
                      {
                          //set to 1 to keep NaN from appearing, cant divide by zero
                          var itemStr = "var" + i.ToString();
                          var rfTemp = "";
                          if (Request.Form[itemStr] == null)
                          {
                              rfTemp = "0";
                              if (i == 3)
                              {
                                  rfTemp = "1";
                              }
                              if (i == 10)
                              {
                                  rfTemp = "1";
                              }
                              if (i == 16)
                              {
                                  rfTemp = "1";
                              }
  
                          }
                          else
                          {
                              rfTemp = Request.Form[itemStr];
                          }
  
                          //put commas after 1st variable in the string for SQL
                          if (i != 1)
                          {
                              frmUpdate += ", ";
                              frmInsert += ", ";
                              frmInsertV += ", ";
                          }
  
  
                          frmUpdate += "s" + i + "= " + rfTemp;
                          frmInsertV += "s" + i;
                          frmInsert += rfTemp;
  
                      }
  
                      var UPSERTcommand = "IF EXISTS (SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "') "
                                          + "UPDATE YieldEncap SET " + frmUpdate + ", QC='" + QC + "' "
                                          + "WHERE ThorneID = '" + ThorneID + "' "
                                          + "ELSE "
                                          + "INSERT INTO YieldEncap (ThorneID, QC, " + frmInsertV + ") "
                                          + "VALUES (" + ThorneID + ", '" + QC + "', " + frmInsert + ")";
                      db.Execute(UPSERTcommand);
  
  
                      UPSERTcommand = "IF EXISTS (SELECT * FROM BR_Details_Yield WHERE ThorneID = '" + ThorneID + "') "
                                         + "UPDATE BR_Details_Yield SET Department = 'Encap', Units = 'g', StartUnits = '" + StartUnits + "', EndUnits = '" + EndUnits + "', Yield = '" + yield + "' "
                                         + "WHERE ThorneID = '" + ThorneID + "' "
                                         + "ELSE "
                                         + "INSERT INTO BR_Details_Yield (Department, Units, StartUnits, EndUnits, Yield) "
                                         + "VALUES ('Encap', 'Bottles', " + StartUnits + ", " + EndUnits + ", " + yield + ")";
                      db.Execute(UPSERTcommand);
                      UPSERTcommand = "";
  
                      sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast&lt;DynamicRecord&gt;().ToArray();
                      RecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'");
  
                      //read out the values from sqlfrmValues and place them in an array
                      if (RecordCount &gt; 0)
                      {
                          for (int i = 1; i &lt;= 26; i++)
                          {
                              if (sqlfrmValues[0][i] != null)
                              {
                                  formValues[i] = Convert.ToDouble(sqlfrmValues[0][i]);
                              }
                              else
                              {
                                  formValues[i] = 0;
                              }
  
                          }
                          QC = Convert.ToString(sqlfrmValues[0][27]);
                      }
                      else
                      {
                          formValues[2] = 1;
                          formValues[10] = 1;
                          formValues[16] = 1;
                          formValues[19] = 1;
                      }
  
                      break;
  
                  default:
                      ThorneID = Request.Form["ThorneID"];
  
                      sqlfrmValues = (db.Query("SELECT * FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'")).Cast&lt;DynamicRecord&gt;().ToArray();
                      var RecordCount2 = (db.Query("SELECT COUNT(*) FROM YieldEncap WHERE ThorneID = '" + ThorneID + "'").Cast&lt;DynamicRecord&gt;().ToArray();
  
                      if (RecordCount[0][0] &gt; 0)
                      {
                          for (int i = 1; i &lt;= 26; i++)
                          {
                              if (sqlfrmValues[0][i] != null)
                              {
                                  formValues[i] = Convert.ToDouble(sqlfrmValues[0][i]);
                              }
                              else
                              {
                                  formValues[i] = 0;
                              }
  
                          }
                          QC = Convert.ToString(sqlfrmValues[0][27]);
                      }
                      else
                      {
                          formValues[6] = 1;
                          formValues[8] = 1;
                          formValues[11] = 1;
                          formValues[24] = 1;
                      }
                      //lookup for previous worksheet. Starting point value
                      //var sqlMixing = (db.Query("SELECT * FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'")).Cast&lt;DynamicRecord&gt;().ToArray();
                      //var sqlMixingRecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'");
                      //if (sqlMixingRecordCount &gt; 0)
                      //{
  
                      //    var temp = Convert.ToDouble(sqlfrmValues[0][1]);
                      //    formValues[1] = Convert.ToDouble(sqlMixing[0][1]);
  
                      //}
  
                      var sqlMixing = (db.Query("SELECT * FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'")).Cast&lt;DynamicRecord&gt;().ToArray();
                      RecordCount = (int)db.QueryValue("SELECT COUNT(*) FROM YieldMixing WHERE ThorneID = '" + ThorneID + "'");
                      if (RecordCount &gt; 0)
                      {
                          formValues[24] = Convert.ToDouble(sqlMixing[0][2]);
                          formValues[24] = formValues[24] * 1000;
                      }
  
                      break;
  
              }
  
          }
      }
  </code></pre>
  
  <p>When it gets to my !DOCTYPE html it tells me "The type or namespace name 'DOCTYPE' could not be could not be found....)
  Likely because it cant figure out where the closing brace is.</p>
  
  <p>Where have I gone wrong? It is very frustrating that the compilers message isnt being helpful because all the braces are correct!</p>