Reputation: 177
I have an C# desktop application which using C++ dll. It's running on .NET 3.5 and working good. The wrapper class using Pinvoke like following:
[DllImport("shapelib", CharSet = CharSet.Ansi, CallingConvention = CallingConvention.Cdecl)]
public static extern void SHPGetInfo(IntPtr hSHP, ref int pnEntities,
ref ShapeType pshpType, double[] adfMinBound, double[] adfMaxBound);
All of wrapper and controller of this application is on class. Now i want to change this application to webservices app. So i build a .net webservices to call a controller and wrapper class. When i run this webservices application on iis 7, Everytime using Pinvoke to call unmanaged dll, i get error: "w3wp error". I used debug diagnostic tool and i show error like following:
In w3wp__DefaultAppPool__PID__1280__Date__11_17_2013__Time_12_37_22PM__300__Second_Chance_Exception_C0000374.dmp the assembly instruction at ntdll!RtlReportCriticalFailure+57 in C:\Windows\System32\ntdll.dll from Microsoft Corporation has caused an unknown exception (0xc0000374) on thread 27
Please help me! Any ideal is appreciate!
PS: thread 27 is Thread 27 - System ID 2032 Entry point mscorwks!Thread::intermediateThreadProc Create time 11/17/2013 12:37:17 PM Time spent in user mode 0 Days 0:0:0.62 Time spent in kernel mode 0 Days 0:0:0.46
Full Call Stack
Function Arg 1 Arg 2 Arg 3 Arg 4 Source
ntdll!RtlReportCriticalFailure+57 c0000374 76facdd8 0324e118 76f9481b
ntdll!RtlpReportHeapFailure+21 00000002 7f19152a 00000000 001e0000
ntdll!RtlpLogHeapFailure+a1 00000008 001e0000 021fc1e8 00000000
ntdll!RtlFreeHeap+64 001e0000 00000000 021fc1f0 76007250
AcXtrnal!NS_FaultTolerantHeap::APIHook_RtlFreeHeap+61 001e0000 00000000 021fc1f0 0324e184
ole32!CRetailMalloc_Free+1c 760066bc 021fc1f0 0324e194 79de7b81 d:\w7rtm\com\ole32\com\class\memapi.cxx @ 687
ole32!CoTaskMemFree+13 021fc1f0 0324e47c 0324e3d0 79deb192 d:\w7rtm\com\ole32\com\class\memapi.cxx @ 475
mscorwks!DefaultMarshalOverrides::ReturnCLRFromNative+35 0324e424 0324e46c 34afa0ec 00f51d3c
mscorwks!RunML+949 00f51d51 0324e46c 0324e428 0324e47c
mscorwks!NDirectGenericStubPostCall+194 00b30ff0 0324e4fc 01883ad8 00f51d51
mscorwks!NDirectGenericStubReturnFromCall+1f 34afa534 018807c0 0ff3af10 00000000
mscorwks!MethodDesc::DoPrestub+515 001e0000 00000000 00b35980 0324e77c
AcXtrnal!NS_FaultTolerantHeap::APIHook_RtlFreeHeap+61 001e0000 00000000 00b35980 0324e748
kernel32!HeapFree+14 001e0000 00000000 79b548ba 34afa474
mscorwks!EEHeapFree+98 001e0000 00000000 00b35980 0324e790
mscorwks!EEHeapFreeInProcessHeap+22 857a0af4 29840fc0 ff000e81 75ff0c75
0x8000000000000000 75ff0c75 9be85008 5dffffff 900008c2
00000000 9be85008 5dffffff 900008c2 c2ca9090
0x80000000
ole32!DeleteACEFromStreamACL+4d 3aec79d0 fadb79de fadb79d0 fb4e79d0 d:\w7rtm\com\ole32\com\accctrl\caccctrl.cxx @ 2425
0x8000000000000000 fadb79d0 fadb79d0 b9f879d0 fadb79bc
00000000 fadb79d0 b9f879d0 fadb79bc fadb79d0
0x80000000
0x8000000000000000 b9f879d0 fadb79bc fadb79d0 4db479d0
00000000 fadb79bc fadb79d0 4db479d0 490879b5
0x80000000
0x8000000000000000 fadb79d0 4db479d0 490879b5 fadb79b7
00000000 4db479d0 490879b5 fadb79b7 fadb79d0
0x80000000
0x8000000000000000 490879b5 fadb79b7 fadb79d0 fadb79d0
00000000 fadb79d0 012279d0 4dd779d8 fadb79da
0x4db479d0 fadb79b7 fadb79d0 fadb79d0 012279d0
0x490879b5 fadb79d0 fadb79d0 012279d0 4dd779d8
0x80000000
0x8000000000000000 012279d0 4dd779d8 fadb79da d14079d0
00000000 4dd779d8 fadb79da d14079d0 fadb79b5
0x80000000
0x012279d0 fadb79da d14079d0 fadb79b5 3aec79d0
0x4dd779d8 d14079d0 fadb79b5 3aec79d0 fadb79de
0x8000000000000000 fadb79b5 3aec79d0 fadb79de fadb79d0
00000000 3aec79d0 fadb79de fadb79d0 fb4e79d0
0x80000000
0x8000000000000000 fadb79de fadb79d0 fb4e79d0 fac779d0
00000000 fb4e79d0 fac779d0 fadb79d0 fadb79d0
0x3aec79d0 fadb79d0 fb4e79d0 fac779d0 fadb79d0
0x80000000
0x8000000000000000 fac779d0 fadb79d0 fadb79d0 b9f879d0
00000000 fadb79d0 fadb79d0 b9f879d0 fadb79bc
0x80000000
0x8000000000000000 fadb79d0 b9f879d0 fadb79bc fadb79d0
00000000 b9f879d0 fadb79bc fadb79d0 4db479d0
0x80000000
0x8000000000000000 fadb79bc fadb79d0 4db479d0 490879b5
00000000 fadb79d0 4db479d0 490879b5 fadb79b7
0x80000000
0x8000000000000000 4db479d0 490879b5 fadb79b7 5a0c79d0
00000000 490879b5 fadb79b7 5a0c79d0 dfb079f7
0x80000000
0x4db479d0 fadb79b7 5a0c79d0 dfb079f7 012279b5
0x490879b5 5a0c79d0 dfb079f7 012279b5 4dd779d8
0x8000000000000000 dfb079f7 012279b5 4dd779d8 fadb79da
00000000 4dd779d8 fadb79da d14079d0 fadb79b5
0x5a0c79d0 012279b5 4dd779d8 fadb79da d14079d0
0x80000000
0x012279b5 fadb79da d14079d0 fadb79b5 3aec79d0
0x4dd779d8 d14079d0 fadb79b5 3aec79d0 dfb079de
0x8000000000000000 fadb79b5 3aec79d0 dfb079de ac7679b5
00000000 3aec79d0 dfb079de ac7679b5 fb4e79bf
0x80000000
0x8000000000000000 dfb079de ac7679b5 fb4e79bf fac779d0
00000000 fb4e79bf fac779d0 fadb79d0 4b1179d0
0x3aec79d0 ac7679b5 fb4e79bf fac779d0 fadb79d0
0x80000000
0x8000000000000000 fac779d0 fadb79d0 4b1179d0 b9f879c0
00000000 fadb79d0 4b1179d0 b9f879c0 fadb79bc
0x80000000
0x8000000000000000 4b1179d0 b9f879c0 fadb79bc fadb79d0
00000000 b9f879c0 fadb79bc fadb79d0 4db479d0
0x80000000
0x4b1179d0 fadb79bc fadb79d0 4db479d0 4b2779b5
0x8000000000000000 fadb79d0 4db479d0 4b2779b5 fadb79c0
00000000 4db479d0 4b2779b5 fadb79c0 fadb79d0
0x80000000
0x8000000000000000 4b2779b5 fadb79c0 fadb79d0 fadb79d0
00000000 fadb79d0 012279d0 4dd779d8 fadb79da
0x4db479d0 fadb79c0 fadb79d0 fadb79d0 012279d0
0x4b2779b5 fadb79d0 fadb79d0 012279d0 4dd779d8
0x80000000
0x8000000000000000 012279d0 4dd779d8 fadb79da f89d79d0
00000000 4dd779d8 fadb79da f89d79d0 296879bd
0x80000000
0x012279d0 fadb79da f89d79d0 296879bd 52d079c1
0x4dd779d8 f89d79d0 296879bd 52d079c1 242f79b5
0x8000000000000000 296879bd 52d079c1 242f79b5 23df79d7
00000000 52d079c1 242f79b5 23df79d7 dfb079d7
0x80000000
0x296879bd 242f79b5 23df79d7 dfb079d7 8de079b5
0x52d079c1 23df79d7 dfb079d7 8de079b5 b44679b6
0x242f79b5 dfb079d7 8de079b5 b44679b6 23ef79e5
0x23df79d7 8de079b5 b44679b6 23ef79e5 7a8279d7
0x8000000000000000 b44679b6 23ef79e5 7a8279d7 e24679bd
00000000 23ef79e5 7a8279d7 e24679bd 7add79b5
0x80000000
0x8000000000000000 7a8279d7 e24679bd 7add79b5 e1b079bd
00000000 e1b079bd 8b5579b5 8b5756ec ff85087d
0x23ef79e5 e24679bd 7add79b5 e1b079bd 8b5579b5
System_ni+5279d7 7add79b5 e1b079bd 8b5579b5 8b5756ec
0x80000000
0x7add79b5 8b5579b5 8b5756ec ff85087d 840ff78b
0x8000000000000000 8b5756ec ff85087d 840ff78b 00038ec7
00000000 ff85087d 840ff78b 00038ec7 8514478b
0x80000000
0x8000000000000000 840ff78b 00038ec7 8514478b 0c4d8bc0
00000000 00038ec7 8514478b 0c4d8bc0 083b0f74
0x80000000
0x8000000000000000 8514478b 0c4d8bc0 083b0f74 483b0b72
00000000 083b0f74 483b0b72 5f067304 08c25d5e
0x00038ec7 0c4d8bc0 083b0f74 483b0b72 5f067304
0x80000000
0x0c4d8bc0 483b0b72 5f067304 08c25d5e 74ff8500
0x083b0f74 5f067304 08c25d5e 74ff8500 760e390b
0x483b0b72 08c25d5e 74ff8500 760e390b 10768b5b
0x5f067304 74ff8500 760e390b 10768b5b f575f685
0x08c25d5e 760e390b 10768b5b f575f685 e7ebc033
0x74ff8500 10768b5b f575f685 e7ebc033 4415ff56
0x760e390b f575f685 e7ebc033 4415ff56 8b7a0af2
0x10768b5b e7ebc033 4415ff56 8b7a0af2 74f685f0
0x8000000000000000 4415ff56 8b7a0af2 74f685f0 08be8318
00000000 8b7a0af2 74f685f0 08be8318 00000002
0x80000000
0x4415ff56 74f685f0 08be8318 00000002 fcde850f
0x80000000`00000000 08be8318 00000002 fcde850f 468b0001
0x74f685f0 00000002 fcde850f 468b0001 0fc08508
0x08be8318 fcde850f 468b0001 0fc08508 01fcc184
Upvotes: 0
Views: 445
Reputation:
It seems there is a problem with the memory allocation on the heap in the unmanaged code which results to the .net framework failing trying to release the allocated memory from the heap. The .Net framework uses different protocol to allocate memory and free memory between managed code and unmanaged code.
You should check your unmanaged C++ dll and replace where you allocate memory (using New or Malloc) and replace it with CoTaskMemAll.
Then ensure that your Pinvoke declaration returns the pointer to the allocated memory, which you must manually release when done with it.
Upvotes: 1