-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PeHeaders FromUnmanagedPtr throws exception #6
Comments
Do you know in context of which Assembly this occurred? Was it a dynamic in-memory assembly? |
All I could pull out of the debugger is that it was a Microsoft Assembly. Didn’t give me much else. The first time calling FromUnmanagedPtr(), the memoryPtr was -1, which caused headers->Load() to actually throw the exception at dosHeader = FromMemoryPtr<IMAGE_DOS_HEADER>(memPtr, index); (values were -1,0). All of the next calls to the method had valid values. System.ServiceModel.CommunicationException: There was an error in serializing body of message DoTransactionRequest: 'There was an error generating the XML document.'. Please see InnerException for more details. ---> System.InvalidOperationException: There was an error generating the XML document. ---> System.InvalidOperationException: Value of ItemElementName mismatches the type of wcf.ws.xxxxxxxxxxxx.xxxxxxxxxxxx; you need to set it to wcf.ws.xxxxxxxxxxxx.xxxxxxxxxxxx.@xxxxxxxxxxxx. at xxxxxxxxxxxx!0x060007c1!ccService.xxxxxxxxxxxx.xxxxxxxxxxxx() +0x20dMODULE: Microsoft.GeneratedCode => Microsoft.GeneratedCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null; Also, in case you want to update the SymbolLoader.cs, the VS 2015 guid is "e6756135-1e65-4d17-8576-610761398c3c" // VS 2015 (msdia140.dll) |
@Critter79606 Thank you very much for the comprehensive information! I think I know what happened, and this is indeed a bug. The module 'Microsoft.GeneratedCode' (which participated in XML serialization) is a generated in-memory assembly, and it does not have HINSTANCE (just as documentation says), would return -1 to indicate that. I should be checking for it, and returning null (since this assembly does not contain debug info anyway). And thanks for the VS 2015 GUID, I'll update it. |
I'm glad I could contribute. I've only just started adding this to my code, but I see it saving me hours of time trying to replicate an issue to find out the exact line that may cause an issue. |
I had an instance where modulePtr was -1 when entering FromUnmanagedPtr(), which threw an exception.
I added the following code to ReadAssemblyDebugInfo()
PeHeaders^ peHdrs = PeHeaders::FromUnmanagedPtr(modulePtr);
if( !peHdrs )
return nullptr;
....
and the following to FromUnmanagedPtr
static PeHeaders^ FromUnmanagedPtr(IntPtr memoryPtr)
{
if( (int)memoryPtr == -1 )
{
return nullptr;
}
....
This resolved the issue.
The text was updated successfully, but these errors were encountered: