title: IL Return in C# returns wrong value
body: <p>I started re-writing my Function Plotter which takes mathematical function and calculates a y value for a given x. To re-write it, I want to dynamically create a method using IL. The test IL code that I have now uses 2 LocalBuilders and multiplies them. However, when i return the value, i receive(what seems to be) a random number instead of the real answer.</p>
  
  <p>Here's the following code that I've been using.</p>
  
  <pre><code>        ILGenerator il = hello.GetILGenerator();
  
          LocalBuilder a = il.DeclareLocal(typeof(int));
          LocalBuilder b = il.DeclareLocal(typeof(int));
          LocalBuilder multOfAandB = il.DeclareLocal(typeof(int));
  
          il.Emit(OpCodes.Ldc_I4, 5); // Store "5" ...
          il.Emit(OpCodes.Stloc, a);  // ... in "a".
  
          il.Emit(OpCodes.Ldc_I4, 6); // Store "6" ...
          il.Emit(OpCodes.Stloc, b);  // ... in "b".
  
          il.Emit(OpCodes.Ldloc, a);
          il.Emit(OpCodes.Ldloc, b); 
  
          il.Emit(OpCodes.Mul);       // Multiply them ...
          il.Emit(OpCodes.Ret);       // ... and return the result.
  </code></pre>
  
  <p>This should return 30 but currently I'm receiving 4.2038953929744512E-44. Is there something wrong with my code thats causing the function to return the wrong value?</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>The code calling the function is as follows:</p>
  
  <pre><code>        object[] invokeArgs = { 42 };
          object obj = func.helloMethod.Invoke(null, BindingFlags.ExactBinding, null, invokeArgs, new CultureInfo("en-us"));
  </code></pre>
  
  <p>and in my class where I store the function to later call it from func.helloMethod has a DynamicMethod which is defined as follows:</p>
  
  <pre><code>DynamicMethod hello = new DynamicMethod("Hello",
              typeof(double),
              helloArgs,
              typeof(double).Module);
  </code></pre>