title: Debug Assertion Failed on \$InstallDir\VC\atlmfc\src\mfc\olelock.cpp line 62 on MFC programming
body: <p>I have to call a sample MFC view in C# application, using Visual Studio 2012. I use C++/CLI project and call C++ class from C#. To do this I have to use this line of code</p>
  
  <pre><code>AFX_MANAGE_STATE(AfxGetStaticModuleState());
  </code></pre>
  
  <p>This will call the resource handle of MFC DLL resource instead of default resource (exe file on C#). The MFC view runs OK, but it appears an exception (as C message box):</p>
  
  <pre><code> Debug Assertion Failed on  \$InstallDir\VC\atlmfc\src\mfc\olelock.cpp line 62 
  </code></pre>
  
  <p>Here is the source code I checked on install Dir:</p>
  
  <pre><code>void AFXAPI AfxOleUnlockApp()
  {
      AFX_MODULE_STATE* pModuleState = AfxGetModuleState();
      ASSERT(pModuleState-&gt;m_nObjectCount != 0);
      if (InterlockedDecrement(&amp;pModuleState-&gt;m_nObjectCount) == 0)
      {
          // allow application to shut down when all the objects have
          //  been released
          ::AfxOleOnReleaseAllObjects();
      }
  }
  </code></pre>
  
  <p>How can I avoid this assertion? Thank you for your support.</p>