VS2002 C++ unboxing a System.Char throws NullReferenceException RRS feed

  • Question

  • I create a Managed C++ Application project in VS2002 and add code to _tmain, as shown below.

    // This is the main project file for VC++ application project
    // generated using an Application Wizard.

    #include "stdafx.h"

    #using <mscorlib.dll>
    #include <tchar.h>

    using namespace System;

    // This is the entry point for this application
    int _tmain(void)
        Char ch = L'z';
        __box Char* bxChar = __box( ch );
        Char ch2 = *bxChar; //** causes NullReferenceException
        return 0;

    The unboxing operation causes a NullReferenceException.  I also tried using the casting operators in the offending line, and received the same error.  What am I missing?  Is there a known issue and/or workaround?

    Thanks in advance for any help.
    • Moved by Paul Zhou Monday, June 27, 2011 10:31 AM (From:.NET Base Class Library)
    Thursday, June 23, 2011 8:40 PM

All replies




    Welcome to the MSDN forum!


    According to your description, I'd like to move your thread to off-topic because it is a problem related to Visual C++. You may post thread in Visual C++ General. There are more experts in that forum so that you may get more useful help there.


    Thank you for your posting and understanding.

    Have a nice day!

    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, June 27, 2011 10:30 AM