Variable is not incrementing in C# Release x64

丶灬走出姿态 提交于 2019-12-08 17:01:56

问题


Could someone explain to me why this piece of code is doing well when I execute it on a x86 platform and why it fail on x64 ?

Results :

  • x86 Debug : 12345678910
  • x64 Debug : 12345678910
  • x86 Release : 12345678910
  • x64 Release : 1111111111

If I change something, like removing one of the unused variables, or if I remove the useless for-loop after p_lFirstId++, the strange behavior disappear.

I found that changing "pdb-only" to "full" in my release configuration, it's work again.

If you run the code directly from visual studio, it's doing well too.

Is this a JIT Compiler bug ?

Thank you in advance.

class Program
{
    static void Main(string[] args)
    {
        Test(null, null, null, 0, 1);            
    }

    public static void Test(
        List<string> liste, List<string> unused1,
        string unused2, int unused3, long p_lFirstId)
    {
        liste = new List<string>();

        StringBuilder sbSql = new StringBuilder();

        for (int i = 0 ; i < 10 ; i++)
        {
            sbSql.Append(p_lFirstId);
            p_lFirstId++;                

            foreach (string sColonne in liste)
            {

            }

        }

        System.Console.WriteLine(sbSql.ToString());
    } 
}

回答1:


This is a bug in the CLR. I would advise contacting Microsoft and asking them to correct this bug in their next release.



来源:https://stackoverflow.com/questions/4715278/variable-is-not-incrementing-in-c-sharp-release-x64

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!