title: NUnit System.OverflowException: Arithmetic operation resulted in an overflow
body: <p>I developed a small Windows Forms application that allows a user to convert between the different values of three temperature scales, Fahrenheit, Celcius and Kelvin.  Being a novice tester, I began dabbling with NUnit and I thought a good way to learn the framework would be to add some testing code to this program.  The class that handles the bulk of the work is :-</p>
  
  <pre><code>public static class TemperatureConverter
  {
      public static ConversionFormula CelciusToFahrenheit = t =&gt; ((t * 1.8) + 32);
  
      public static ConversionFormula CelciusToKelvin = t =&gt; (t + 273);
  
      public static ConversionFormula FahrenheitToCelcius = t =&gt; ((t - 32) * 5/9);
  
      public static ConversionFormula FahrenheitToKelvin = t =&gt; (t + 459.67)/1.8;
  
      public static ConversionFormula KelvinToCelcius = t =&gt; (t - 273);
  
      public static ConversionFormula KelvinToFahrenheit = t =&gt; (t * 9/5 - 459.67);
  
  
      public static double ConvertTemperature(double temperatureValue, ConversionFormula conversionFormula)
      {           
          return conversionFormula(temperatureValue);
      }
  }
  </code></pre>
  
  <p>I started off by simply testing individual temperature values were converting correctly.  Eventually this became tiring and involved a lot of repetitive code, so  rather than writing one test per value, I used NUnit’s ‘Range’ and ‘Values’ attribute so I could test in batches of ten.  An example test method is:- </p>
  
  <pre><code>[TestFixture]
  public class Class1
  {
      private ConversionFormula _fahrenheitToCelcius;
  
      [SetUp]
      public void Init()
      {
          _fahrenheitToCelcius = TemperatureConverter.FahrenheitToCelcius;
      }
  
      #region Fahrenheit To Celcius Positive Values
  
      [Test, Sequential]
      public void ConvertFahrenheitToCelciusRange_0_To_10_RoundedTo2DP([Range(0, 10, 1)]double temperature,
                  [Values(-17.78, -17.22, -16.67, -16.11, -15.56, -15, -14.44, -13.89, -13.33, -12.78, -12.22)]double expected)
      {
          double actual = TemperatureConverter.ConvertTemperature(temperature, _fahrenheitToCelcius);
  
          Assert.AreEqual(expected, actual, 1);
      }
  </code></pre>
  
  <p>The range values are the temperatures to test, in this case, from 0 to 10.  The values attribute contains the expected result for each test.  I am using NUnit 2.6.2 and Resharper Test Runner.  I added almost identical test methods in the one class file that stepped up the temperature range in values of ten.  For example, the next test would be :-</p>
  
  <pre><code>[Test, Sequential]
      public void ConvertFahrenheitToCelciusRange_11_To_20_RoundedTo2DP([Range(11, 20, 1)]double temperature,
                  [Values(-11.67, -11.11, -10.56, -10, -9.44, -8.89, -8.33, -7.78, -7.22, -6.67)]double expected)
      {
          double actual = TemperatureConverter.ConvertTemperature(temperature, _fahrenheitToCelcius);
  
          Assert.AreEqual(expected, actual, 1);
      }
  </code></pre>
  
  <p>After each test was added, I ran it to see if it passed and it did.  Eventually, I ended up testing through ranges 0 - 150, so I had a total of 15 test methods per class.  Now a problem occurs.  Both the Resharper test runner and the NUnit test runner randomly reports </p>
  
  <blockquote>
    <p>NUnit  System.OverflowException: Arithmetic operation resulted in an overflow</p>
  </blockquote>
  
  <pre><code>    System.OverflowException...
  
  Server stack trace: 
     at NUnit.Framework.RangeAttribute..ctor(Int32 from, Int32 to, Int32 step)
     at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule, IRuntimeMethodInfo pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
     at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module, IRuntimeMethodInfo ctor, IntPtr&amp; blob, IntPtr blobEnd, Int32&amp; namedArgs)
     at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes, Boolean isDecoratedTargetSecurityTransparent)
     at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeParameterInfo parameter, RuntimeType caType)
     at NUnit.Core.Reflect.GetAttributes(ICustomAttributeProvider member, Boolean inherit)
     at NUnit.Core.Reflect.HasAttribute(ICustomAttributeProvider member, String attrName, Boolean inherit)
     at NUnit.Core.Builders.ValueSourceProvider.HasDataFor(ParameterInfo parameter)
     at NUnit.Core.Extensibility.DataPointProviders.HasDataFor(ParameterInfo parameter)
     at NUnit.Core.Builders.CombinatorialTestCaseProvider.HasTestCasesFor(MethodInfo method)
     at NUnit.Core.Extensibility.TestCaseProviders.HasTestCasesFor(MethodInfo method)
     at NUnit.Core.Builders.NUnitTestCaseBuilder.BuildFrom(MethodInfo method, Test parentSuite)
     at NUnit.Core.Extensibility.TestCaseBuilderCollection.BuildFrom(MethodInfo method, Test suite)
     at NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildTestCase(MethodInfo method, TestSuite suite)
     at NUnit.Core.Builders.NUnitTestFixtureBuilder.AddTestCases(Type fixtureType)
     at NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildSingleFixture(Type type, Attribute attr)
     at NUnit.Core.Builders.NUnitTestFixtureBuilder.BuildFrom(Type type)
     at NUnit.Core.Extensibility.SuiteBuilderCollection.BuildFrom(Type type)
     at NUnit.Core.TestFixtureBuilder.BuildFrom(Type type)
     at NUnit.Core.Builders.TestAssemblyBuilder.GetFixtures(Assembly assembly, String ns)
     at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, Boolean autoSuites)
     at NUnit.Core.Builders.TestAssemblyBuilder.Build(String assemblyName, String testName, Boolean autoSuites)
     at NUnit.Core.TestSuiteBuilder.BuildSingleAssembly(TestPackage package)
     at NUnit.Core.TestSuiteBuilder.Build(TestPackage package)
     at NUnit.Core.SimpleTestRunner.Load(TestPackage package)
     at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
     at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
     at NUnit.Core.RemoteTestRunner.Load(TestPackage package)
     at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]&amp; outArgs)
     at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
  
  Exception rethrown at [0]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at NUnit.Core.TestRunner.Load(TestPackage package)
     at NUnit.Util.TestDomain.Load(TestPackage package)
     at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
     at NUnit.Util.RemoteTestAgent.AgentRunner.Load(TestPackage package)
     at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]&amp; outArgs)
     at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)
  
  Exception rethrown at [1]: 
     at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
     at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData&amp; msgData, Int32 type)
     at NUnit.Core.TestRunner.Load(TestPackage package)
     at NUnit.Core.ProxyTestRunner.Load(TestPackage package)
     at NUnit.Util.ProcessRunner.Load(TestPackage package)
     at NUnit.Util.TestLoader.LoadTest(String testName)
  </code></pre>
  
  <p>No matter how many times I try to re-run the tests, I get the same error.  Not only that, all other test files in the assembly that were working perfectly fine, now report the same problem.  At first I assumed it was a problem with the values passed into the Values or Range attributes, but to put this to the test, I created a fresh new assembly, added a reference to NUnit and copied and pasted the tests from my original assembly, to the new one.  Hey presto, the tests all run fine.  Now If I make no changes to the test file in the new assembly and run the tests from time to time, eventually I am greeted with the same error.  Not only that, all other test classes break again also. The only way around this is to create a fresh assembly and copy and past the old test files across.  This is no good as they will eventually break again.  I am an NUnit newby, so if anyone has come across this error before or can understand what I might be doing wrong here, then your advice would be greatly appreciated.  </p>