我有一段代码:
private void AnswerToCe(int currentBlock, int totalBlock = 0)
{
byte[] bufferToSend;
byte[] macDst = mac;
byte[] macSrc = ConnectionManager.SInstance.GetMyMAC();
byte[] ethType;
byte[] header;
if (Function == FlashFunction.UPLOAD_APPL || Function == FlashFunction.UPLOAD_BITSTREAM)
{
ethType = BitConverter.GetBytes((ushort)EthType.ETH_TYPE_UPLOAD);
ethType = new byte[] { ethType[1], ethType[0] };
header = Header.GetBytes((ushort)binaryBlocks.Count, (ushort)(currentBlock + 1), (ushort)binaryBlocks[currentBlock].Length);
int index = 0;
bufferToSend = new byte[macDst.Length + macSrc.Length + ethType.Length + header.Length + binaryBlocks[currentBlock].Length];
Array.Copy(macDst, 0, bufferToSend, index, macDst.Length);
index += macDst.Length;
Array.Copy(macSrc, 0, bufferToSend, index, macSrc.Length);
index += macSrc.Length;
Logger.SInstance.Write(index.ToString(), "test index pre");
Array.Copy(ethType, 0, bufferToSend, index, ethType.Length);
index += ethType.Length;
Logger.SInstance.Write(index.ToString(), "test index post");
Array.Copy(header, 0, bufferToSend, index, header.Length);
index += header.Length;
Array.Copy(binaryBlocks[currentBlock], 0, bufferToSend, index, binaryBlocks[currentBlock].Length);
}如果我在调试模式下构建我的应用程序,一切正常,test index pre打印12,test index post打印14。在发布模式中,Optimize code不加检查。如果我用Optimize code进行测试,检查test index post打印18,而不是14。
如果我用index += ethType.Length;替换index += 2;,结果也是一样的。似乎只有index++;index++;在工作。
我在一个空的应用程序中尝试了这段代码,和是可以的。
应用程序是多线程的,但是这里没有并发性。
从DLL中解压缩代码似乎没问题。
知道为什么会这样吗?
编辑:只有在为x64编译应用程序时才会发生。x86没事。
编辑3:构建env的一些信息:
visual 15.0.0-RTW+26228.4
框架4.7.02053
可以在框架4.6.2和4.7上触发此问题。其他框架没有经过测试。
编辑5:新的、较小的示例项目。不需要依赖关系。
编辑6:拆卸测试项目这里。(时间太长,无法在此张贴)
发布于 2017-08-04 08:11:33
这是RyuJIT中已经报告的一个bug,更详细的这里。很快就会被修复。
https://stackoverflow.com/questions/45461443
复制相似问题