c++visual-studio-2022clrupdates

My CPP/CLR Form-application crashes after updating Visual Studio 2022


A couple of days ago I updated VS 2022 to its latest version 17.11.2.
This version was released just about the same time.

Now when I build and run my C++/CLR Form application I receive crashes inside ntdll.dll.
This happens in two different applications I have, which were both fully functioning up to this update.

The crash is before any of my code is running.
My breakpoint on first line of main is never reached.

The crash is during CLR application startup:

ntdll.dll!00007fffd90af6e0()    Unknown
KernelBase.dll!00007fffd6a351bb()   Unknown
ucrtbased.dll!00007fff0f6b24d7()    Unknown
ucrtbased.dll!00007fff0f6b2f1e()    Unknown
MyApp.exe!_onexit(int(*)() function=0x00007ff6ea6d0f20) Line 267    C++
MyApp.exe!atexit(void(*)() function=0x00007ff6ea6d0f20) Line 275    C++
MyApp.exe!std::`dynamic atexit destructor for '_Fac_tidy_reg''() Line 64    C++
[Managed to Native Transition]  
MyApp.exe!_initterm(void (__cdecl*)()* pfbegin=0x00000052842fdc40, void (__cdecl*)()* pfend=0x00000052842fdc48) Line 126    C++
MyApp.exe!<CrtImplementationDetails>::LanguageSupport::InitializeNative() Line 359  C++
MyApp.exe!<CrtImplementationDetails>::LanguageSupport::_Initialize() Line 598   C++
MyApp.exe!<CrtImplementationDetails>::LanguageSupport::Initialize() Line 805    C++
MyApp.exe!.cctor() Line 857 C++
[Native to Managed Transition]  
[Managed to Native Transition]  
[Native to Managed Transition]  
mscoreei.dll!00007fffbb50d6ea() Unknown
mscoree.dll!00007fffbc7aac42()  Unknown
kernel32.dll!00007fffd7ee7374() Unknown
ntdll.dll!00007fffd909cc91()    Unknown

If anyone know how to work-around this please let me know.
Also - if there a way to roll-back to a specific previous release please let me know.

Meanwhile beware of this specific version...


Solution

  • Apparently this is a regression that came with one of the last Visual Studio 2022 Community updates. I am not sure exactly with which one, as I did not update my VS for a while, but I noticed it after updating to 17.11.2.

    Context
    Until now, in a C++/CLI application, you could select a different clr runtime support per each C++ file. Typically you would select No CLR support for C++ files containing pure native code, and /clr for files, which need to utilize .NET libraries.

    These settings are done using the Common Language Runtime Support option, found under Project Settings | C/C++ | General.
    This setting can be done per C++ file:

    Selecting runtime-support for C++ file

    The Bug
    As from this regression, if you select No Common Language Runtime Support for some of your C++ files, you could receive the runtime crash reported above.

    Workaround
    Set all your files to /clr.
    This may issue the following warning for some of your functions, but apart from this all will work:

    warning C4793: 'foo': function compiled as native