title: C# CLR Stored Proc won't Deploy to SQL Server 2005
body: <p>I'm developing a C# SQL Server 2005 stored procedure that does data validation for my application.  I have a nice framework built, that is working.  The validation methods are along the lines of:</p>
  
  <pre><code>private void TestDate() {
      TestFields(delegate (string value) {
          if (value == String.Empty || value == "")
              return true;
          return IsDate(value);
      });
  }
  </code></pre>
  
  <p>The solution compiles, deploys, and runs fine with several methods written like the above.  TestFields iterates over the columns returned by a query, calling the delegate that returns whether or not the validity test is passed. I added a new method:</p>
  
  <pre><code>private void TestRequired() {
      TestFields(delegate (string value) {
          return ! (value == String.Empty || value == "");
      });
  }
  </code></pre>
  
  <p>With this method, the DLL won't deploy: CREATE ASSEMBLY failed because method 'TestRequired' on type 'SurveyValidator'  in safe assembly 'SurveyValidation' is storing to a static field. Storing to a static field is not allowed in safe assemblies. </p>
  
  <p>I'm pulling out my hair.  If I comment out TestRequired(), it works. Obviously, it's not doing an assignment statement, so I don't know what SQL Server is complaining about.  Did I just stumble onto some kind of obscure bug?  (I know what the error means, I don't have any static fields in the SP class.  Just the static entry method that creating the project gives you.)</p>
  
  <p>TIA,
  Dave</p>