Search code examples
c#.netc++-cliunmanagedmanaged-c++

Unmanaged code calling causes a WCF process to crash


I have a class which includes managed code calling to unmanaged code via C++\CLI wrapper. Where running the class in a console application produces no errors.
But when I wrapped it up with a WCF service the application crashes when the code reaches the point of calling unmanaged code.

The problem is when passing a const wchar_t* variable as input to the unmanaged code:

String^ text = … // Unicode Encoded text;  
const wchar_t* chars = reinterpret_cast<const wchar_t*>    ((Marshal::StringToHGlobalUni(string)).ToPointer());  
unmanaged_class::Process(chars);   

Also tried this with no luck:

pin_ptr<const wchar_t> chars = ...  

The application just shutdown without any exception.

I am working on Windows Server 2008 64 bit machine with .NET 4.0.
The application is configured to run on 64bit platform.

Any ideas?

Cheers, Doron.


Solution

  • It seems that the problem was buried in the unmanaged code which is 3rd party code who had a bug and crashed in this scenario.