Can anyone help me with this? I’m getting an assert error when I exit out of my main app (C#) after calling my dll (C++). The error is Debug Assertion Failed! Program:… File: f:\...appcore.cpp Line: 862. I’ve researched this problem and it appears I needed AFX_MANAGE_STATE(AfxGetStaticModuleState()); which is the first line in the dll function but the problem still exists. I also am using debug versions on my main app and dll. This assertion error only occurs when I’m calling a function that generates a dialog box (CDialog). When I call other functions that do some calculations there are no errors. I’m using Visual Studio V2005. Here are the code excerpts. Thanks in advance. Code: /// code from assertion appcore.cpp // Cleanup DAO if necessary if (m_lpfnDaoTerm != NULL) { // If a DLL, YOU must call AfxDaoTerm prior to ExitInstance ASSERT(!afxContextIsDLL);//here is where things stop (*m_lpfnDaoTerm)(); } /// code from DLL (uses MFC as shared DLL) extern "C" int EXPORT Get_The_Material(char *MaterialName); { //Microsoft suggests this macro to be called first, see above AFX_MANAGE_STATE(AfxGetStaticModuleState()); if (IDOK == FM.DoModal()) { if (FM.iItem != -1) { // user selected a material ……… rest of code }} Return 1; /// code from C# calling application namespace WindowsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("MyDLL.dll")] unsafe private static extern int Get_The_Material(byte[] TradeName); unsafe private void btnMyDLL_Click(object sender, EventArgs e) { byte[] TradeName; TradeName = new byte[50]; Get_The_Material(TradeName); …. Rest of code }