Un'applicazione costruita su computer di compilazione notturna non funziona su Windows Server 2012 ma funziona correttamente su altri desktop.I file binari creati su Windows 7 non riescono su Windows Server 2012
Un'eccezione del tipo "Tentativo di leggere o scrivere memoria protetta. Ciò è spesso un'indicazione che altra memoria è corrotta." viene lanciato
Quando eseguo il debug utilizzando il debug remoto sul computer WindowsServer2012 e sulla macchina di compilazione, vedo che questa eccezione viene generata in un punto in cui il codice 3232 chiama HeapSize nel codice. Ecco come HeapSize
viene importato e chiama:
[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;
}
Questo è chiamato come parte di costruttore di una classe non sicuro:
public UnManagedBuffer(StringBuilder sb)
{
PtrStart = (byte*)Marshal.StringToHGlobalAnsi(sb.ToString());
Size = UnManagedMemory.SizeOf(PtrStart);
PtrWriteNextValue = PtrStart + Size - 1;
PtrReturnNextValue = PtrStart;
}
Degli indizi su quello che potrebbe essere mancante e come risolvere questo problema?
Questo è quello che vedo in Windbg:
EventLog mostra:
Log Name: Application
Source: .NET Runtime
Level: Error
Keywords: Classic
Description:
Application: TestEngine.exe
Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.AccessViolationException
at Core.Utils.UnManagedMemory.HeapSize(Int32, Int32, Void*)
at Core.Utils.UnManagedMemory.SizeOf(Void*)
at Core.Utils.UnManagedBuffer..ctor</Event>
Faulting application name: TestEngine.exe, version: 1.0.0.0, time stamp: 0x56b532bb
Faulting module name: ntdll.dll, version: 6.3.9600.18185, time stamp: 0x5683f0c5
Exception code: 0xc0000005
Fault offset: 0x0000000000057306
Faulting process id: 0x2eb8
Faulting application start time: 0x01d164e45b12d7dd
Faulting application path: C:\NGDLM\Lib\TestEngine.exe
Faulting module path: C:\Windows\SYSTEM32\ntdll.dll
Report Id: bea6eb89-d0d7-11e5-80eb-0050568cd888
Faulting package full name:
Faulting package-relative application ID:
Si sta utilizzando PInvoke chiamare HEAPSIZE? Puoi mostrare la dichiarazione del metodo? (Inoltre, tutte le macchine hanno la stessa architettura, cioè x86 vs x64?) – stuartd
Fai un crash dump, colpiscilo con [windbg + SOS] (https://blogs.msdn.microsoft.com/kaevans/2011/04/11/intro-to-windbg-per-net-developers /) –
Sì, la configurazione è la stessa: entrambe le macchine sono x64 e il codice è costruito in x64 config. Il codice è: [DllImport ("kernel32")] statico extern int HeapSize (int hHeap, int flags, void * block); // Restituisce la dimensione di un blocco di memoria. public static int SizeOf (void * block) { int result = HeapSize (ph, 0, block); if (result == -1) lanciare InvalidOperationException(); risultato di ritorno; } – NVK