Why is CreateManagedControl access-violating after upgrading from .Net 4.6.1 to .Net 5?

1

I have an MFC app containing a C++/CLI project that calls MFC::CWinFormsControl<MyWidget>::CreateManagedControl() to create a control written in C#. This worked fine under .Net Framework 4.6.1, but now I have upgraded the C++/CLI and C# projects to .Net 5 it causes an access violation:

Exception thrown at 0x00007FFC81A3F528 (clr.dll) in MyApp.exe: 0xC0000005: Access violation reading location 0x0000000000000000.

Stack trace:

mfc140ud.dll!COleControlSite::CreateControlCommon(CWnd * pWndCtrl, const _GUID & clsid, const CControlCreationInfo & creationInfo, const wchar_t * lpszWindowName, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID, CFile * pPersist, int bStorage, wchar_t * bstrLicKey) Line 224 C++
mfc140ud.dll!COleControlSite::CreateControl(CWnd * pWndCtrl, const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID) Line 198  C++
mfc140ud.dll!COleControlContainer::CreateControlCommon(CWnd * pWndCtrl, const _GUID & clsid, const CControlCreationInfo & creationInfo, const wchar_t * lpszWindowName, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID, CFile * pPersist, int bStorage, wchar_t * bstrLicKey, COleControlSite * * ppNewSite) Line 301 C++
mfc140ud.dll!COleControlContainer::CreateControl(CWnd * pWndCtrl, const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, unsigned int nID) Line 270 C++
mfc140ud.dll!CWnd::CreateControl(const CControlCreationInfo & creationInfo, unsigned long dwStyle, const tagPOINT * ppt, const tagSIZE * psize, CWnd * pParentWnd, unsigned int nID) Line 90    C++
[Managed to Native Transition]  
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::InternalCreateManagedControl(CControlCreationInfo& info, unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 122  C++
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::CreateManagedControl(System::Type^ pType, unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 133 C++
CLI.dll!Microsoft::VisualC::MFC::CWinFormsControl<Widget::MyWidget>::CreateManagedControl(unsigned int dwStyle, tagRECT& rect, CWnd* pParentWnd, int nID) Line 149  C++
CLI.dll!Cli::CreateControl(CWnd* parent, int id) Line 191   C++

Other C# functionality works without a hitch, as does an experimental gcnew Widget::MyWidget(). I've been experimenting with project settings for some time but am getting nowhere. Any ideas?

mfc
controls
c++-cli
upgrade
.net-5
asked on Stack Overflow May 17, 2021 by tombola

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0