Quantcast
Channel: Active questions tagged nuget-package - Stack Overflow
Viewing all articles
Browse latest Browse all 3171

C# when deploid as nuget package a simple calculation gives wrong results

$
0
0

The following function

public int GetNumber(){    int num = (condition1 ? 3 : (condition2 ? 1 : 2));    int num2 = (condition3 ? 6 : (condition4 ? 3 : 0));    return num + num2;}

returns the correct result when run in tests.But when I include it in a NuGet package and reference it in another project it sometimes gives wrong results,e.g. for condition 1 and 2 it sets num = 1and condition 3 and 4 sets num2 = 0which is correct but it returns 4 and I have no clue why it does that.

I tried to set a variable in between but VS optimizes it by removing that variable during the build. The code above is somewhat what build has made. I have set breakpoints in the code trying to find out the problem.

The original code is

      public int Get9Box(Measurements measurements, Parameters parameters)      {         int bathBox = 0;         int liquidusBox = 0;         if (measurements.CurrentBathTemperature > parameters.BathTargetTemperature + parameters.DeadBand)         {            bathBox = 3;         }         else if (measurements.CurrentBathTemperature < parameters.BathTargetTemperature - parameters.DeadBand)         {            bathBox = 1;         }         else         {            bathBox = 2;         }         if (measurements.AverageLast4Liquidus > parameters.LiquidusTargetTemperature + parameters.DeadBand)         {            liquidusBox = 6;         }         else if (measurements.AverageLast4Liquidus < parameters.LiquidusTargetTemperature - parameters.DeadBand)         {            liquidusBox = 0;         }         else         {            liquidusBox = 3;         }         int result = bathBox + liquidusBox;         return result;      }

Viewing all articles
Browse latest Browse all 3171

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>