CInternetSession Debug Assertion Failed (Fixed)

I had completely forgotten about the Debug Assertion Failure when invoking the MFC CInternetSession from a console application.

I recently needed to teach an Old Dog a New Trick by performing an MFC FTP upload from a .NET (C#) console application.

When running the app in debug mode, I got the "Debug Assertion Failed" dialog box that requires an answer of Abort, Retry or Ignore.

I remembered (from long ago) this is a benign error and can just be ignored (if you want to press a button), but I didn't want any surprises and I wanted "clean" code.

In the rare instance someone else might run across this, here is the SHORT solution:

  1. Modify your header to include <afx.h>, <afxinet.h> and <afxwin.h>
  2. Add a module-level instance of CWinApp (yes, even in a console app).
  3. Set a value in your code for the variable afxCurrentAppName before invoking the CInternetSession

Here is the LONG solution

The error reported says there is a failure in the file afxwin1.inl at line 29.
After some disk searching, I found the file, afxwin1.inl, and saw the problem line 29:

...which simply checks to see if the variable afxCurrentAppName has a value.

afxCurrentAppName is an alias for AFX_MODULE_STATE::m_lpszCurrentAppName of type LPCTSTR in file afxstat_.h that is NOT automatically when making a console app (deeper explanation not given in this post).

Here's a test line of code that will cause the error:

Here is the dialog box showing the Debug Assertion Failure:

Here are the modifications to stop the error:
First, modify the header:

...then modify the code:

I have not run across any negative side-effects by doing this.

posted @ Friday, December 18, 2009 1:08 PM

Comments on this entry:

# re: CInternetSession Debug Assertion Failed (Fixed)

Left by Derrick at 1/27/2010 10:09 AM
Thanks, this was helpful.

# re: CInternetSession Debug Assertion Failed (Fixed)

Left by Patrick at 9/9/2011 5:38 PM
Thank you!! This was VERY helpful and fixed my problem. You provided a much needed understanding of what and why this issue was happening.

# re: CInternetSession Debug Assertion Failed (Fixed)

Left by Frank at 10/30/2012 10:59 AM
That did it for me. Thanks alot.

# Debug Assertion Failed

Left by Mohammad Shadab Ansari at 5/6/2013 4:29 AM
Programe: Flash loader 7.2.4 SEC 2.4 Lite And Slave 0.4.exe
File: filetx.cpp
Line: 233

# re: CInternetSession Debug Assertion Failed (Fixed)

Left by Stuart Mitchell at 12/7/2016 5:04 AM
This is great!!! Thank you so much.

Your comment:

(not displayed)


Live Comment Preview: