Getting exception in SysFreeString ONLY when application is developed on .NET framework 4.5.2(VS2015). RRS feed

  • Question

  • I have a COM class, say ThisClass with two CComBSTR data members- say bstr1 and bstr2 and several functions, all written in C++. I am using the Interop file of this library in an application written in c#. The application works fine when built on .NET Framework 4.0(using VS2010). But when I run it after building on .NET Framework 4.5.2(using VS2015), it crashes intermittently. It crashes sometimes in the destructor of ThisClass (not for every destructor call).The destructor of the class has SysFreeString call for both bstr1 and bstr2. On debugging I found that the crash happens at SysFreeString. It says Exception at ntdll-SysFreeString-A heap has been corrupted. But I logged the data before the SysFreeString command, and both the data values are correct. 

    Could anyone please assist me on this one?

    Thank you!

    Thursday, February 25, 2016 11:21 AM

All replies

  • Hi ShockWave,

    According to your description, your case more related to SysFreeString in .NET framework 4.5.2. I would suggest you to make a simplified demo to reproduce your issue.

    Please also make a clean machine to test. If only .Net Framework 4.5.2 has this issue, how about the result in .Net framework 4.6? Please  also make a test.

    If all are prove this is a bug, please report this issue to MS through Connect website where some engineer from MS will help you fix it.

    In addition, if you finish submit this issue, please remember to post the link here, I will help you vote it.

    Best regards,



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Friday, February 26, 2016 5:37 AM
  • If you are using ATL's CComBSTR class then SysFreeString will be called automatically in the CComBSTR object's destructors.

    The heap corruption is likely caused by SysFreeString being called twice. It is called by you in the destructor of ThisClass and then again by the CComBSTR destructor.

    Tuesday, March 1, 2016 4:40 PM