在夜间构建计算机上构建的应用程序在Windows Server 2012上不起作用,但在其他桌面上运行正常.
"尝试读取或写入受保护的内存"的例外情况.这通常表明其他内存已损坏.被扔了.
当我在WindowsServer2012机器和构建机器上使用远程调试进行调试时,我看到在代码中调用了kernel32调用HeapSize的地方抛出了这个异常.以下是HeapSize导入和调用的方式:
[DllImport("kernel32")]
static extern int HeapSize(int hHeap, int flags, void* block);
// Returns the size of a memory block.
public static int SizeOf(void* block)
{
int result = HeapSize(ph, 0, block);
if (result == -1) throw new InvalidOperationException();
return result;
}
Run Code Online (Sandbox Code Playgroud)
这被称为不安全类的构造函数的一部分:
public UnManagedBuffer(StringBuilder sb)
{
PtrStart = (byte*)Marshal.StringToHGlobalAnsi(sb.ToString());
Size = UnManagedMemory.SizeOf(PtrStart);
PtrWriteNextValue = PtrStart + Size - 1;
PtrReturnNextValue = PtrStart;
}
Run Code Online (Sandbox Code Playgroud)
关于什么可能遗失的任何线索以及如何解决这个问题?
这就是我在Windbg中看到的:
EventLog显示:
Log Name: Application
Source: .NET Runtime …Run Code Online (Sandbox Code Playgroud)