A managed application may crash silently when an unmanaged C++ client passes a NULL pointer to receive an array output parameter. RRS feed

  • General discussion

  • Symptoms

    Consider the following scenario:


    You migrate existing unmanaged COM codes to managed codes;

    A com visible .NET component in the codes has a method which returns an array as an out parameter;

    The method is called by an unmanaged C++ client with a NULL pointer to receive the output parameter.

    In this scenario, an access violation occurs in the CLR  runtime and the managed application will crash silently.


    NOTE: When the same code happens to unmanaged COM codes, you will get an exception or an HRESULT such as E_POINTER.




    The problem happens because the NULL pointer check is missed by the Interoperability layer in managed codes.






    The method in the .NET code that is expecting an array should check whether a NULL value is passed.




    The client that is calling the method should check whether the passed value for output parameter is NULL.



    Intended Audience




    © 2009 Microsoft Corporation. All rights reserved.

    • Changed type Zhi-Xin Ye Monday, August 31, 2009 7:52 AM
    • Changed type Zhi-Xin Ye Monday, September 7, 2009 3:10 AM
    Monday, August 31, 2009 5:28 AM