Solved

What does "Application popup: Assertion Failed:" indicate?

Posted on 2008-10-23
28
2,275 Views
Last Modified: 2013-12-17
I am running a C# asp.net project in Visual Studio 2005.  Everything works fine on my computer, but in staging, the app seems to hang and the event log (Event ID 26) has the error you see in the snippet.  Ive also added the offending code in the snippet following the event log details.

I asked a very similar question before, but I cant seem to figure out why the event log is generating this error.  I briefly got the app to work in staging after I tried debugging on the machine, but it is not consistent.  (see - http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/Q_23809385.html)

Any help would be appreciated.
Application popup: Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue : 
 
 
    at SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values)  
    at employees.GetActiveEmployees()  
    at addcase.Page_Load(Object sender, EventArgs e)  
    at CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)  
    at CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)  
    at Control.OnLoad(EventArgs e)  
    at ControlAdapter.OnLoad(EventArgs e)  
    at Control.LoadRecursive()  
    at Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
    at Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
    at Page.ProcessRequest()  
    at Page.ProcessRequestWithNoAssert(HttpContext context)  
    at Page.ProcessRequest(HttpContext context)  
    at addcase_aspx.ProcessRequest(HttpContext context)  
    at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
    at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
    at ApplicationStepManager.ResumeSteps(Exception error)  
    at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)  
    at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)  
    at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)  
    at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)  
 
 
//This is the code that appears to be creating the event log error
    [SqlCommandMethod(CommandType.StoredProcedure)]
    public static SqlCommand procGetActiveEmployees(
     [NonCommandParameter] SqlConnection connection)
    {
        return SqlCommandGenerator.GenerateCommand(connection, null, SqlCommandGenerator.NoValues);
    }

Open in new window

0
Comment
Question by:clintfield
  • 15
  • 13
28 Comments
 
LVL 8

Expert Comment

by:the_crazed
ID: 22812156
are you using the SqlCommandGenerator as provided here?
http://msdn.microsoft.com/en-us/magazine/cc301780.aspx

the author says he's written it so it'll give an assertion failure if you miss out the SqlCommandMethod Attribute.
hmmm... you seem it have included the required attbute...

maybe his code does more that he's letting on... maybe it also checks for existence of the sp... does the procedure "procGetActiveEmployees" exist on staging?
I can't seem to download the code that comes with the article - please could you post the code from SqlCommandGenerator?


 
0
 
LVL 1

Author Comment

by:clintfield
ID: 22812330
Thanks for the reply.  
Yes, the sproc is in staging and Ive actually used this code in many other apps without any issues.  I should have mentioned that I test on my local box, which connects to the staging db.  So the code works on my local machine while connecting to the staging db.  Then I publish the code to staging....and everything just hangs on pages that call the same db that was working from my local box!  Ive even got the same code in other apps on the same staging server!  
I posted the whole code trail in the snippet below.

//aspx page
                DataTable dt = new DataTable();
                dt = employees.GetActiveEmployees();
//class file
    public static DataTable GetActiveEmployees()
    {
 
 
        DataTable dtS = new DataTable("S");
 
        try
        {
            using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["OutReachConnectionString"].ConnectionString))
            {
                con.Open();
                SqlCommand cmd = new SqlCommand();
                cmd = sprocs.procGetActiveEmployees(con);
                SqlDataAdapter objDa = new SqlDataAdapter(cmd);
                objDa.Fill(dtS);
                objDa.Dispose();
            }
        }
        catch (SystemException)
        {
            throw;
        }
 
        return dtS;
 
    }
 
 
//sprocs class
    [SqlCommandMethod(CommandType.StoredProcedure)]
    public static SqlCommand procGetActiveEmployees(
     [NonCommandParameter] SqlConnection connection)
    {
        return SqlCommandGenerator.GenerateCommand(connection, null, SqlCommandGenerator.NoValues);
    }

Open in new window

0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22814684
do you have acess to the code within SqlCommandGenerator?
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
LVL 1

Author Comment

by:clintfield
ID: 22814912
Yep.  See the snippet below.
 
 

using System;
using System.Data.SqlClient;
using System.Reflection;
 
namespace dbreflection.Data.Sql
{
    public sealed class SqlCommandGenerator
    {
        public static readonly object[] NoValues;
        public static readonly string ReturnValueParameterName;
 
        public static SqlCommand GenerateCommand(SqlConnection connection, MethodInfo method, object[] values);
    }
}

Open in new window

0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22816754
how many params does procGetActiveEmployees have? none?
0
 
LVL 1

Author Comment

by:clintfield
ID: 22820378
No params for this call.
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22821265
sorry, I'm stuck. You've done everything right, I can see no reason for this assert to show. The trouble is, it seems that someone has written an Assert into the GenerateCommand code, without filling in the second parameter (this is where the developer adding the Assert should write the reason for it).

As a workaround (this only hides the problem I'm afraid), build your project in "Release" mode; none of the Debug commands such as Assert get compiled in, so your code will run without a problem. Ideally though, you need to find the Debug.Assert line and find out what the heck it thinks its doing.
0
 
LVL 1

Author Comment

by:clintfield
ID: 22823102
I was hoping you were on to something with the "Release" mode.  But unfortunately that didnt work.  Great try though!
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22823921
you are still getting the "Assert" when compiling in "Release" Mode? this should not be the case.
Does the GenerateCommand code perhaps live in an external library which has not been compiled in Release mode? If so, would you be able to get this recompiled?
0
 
LVL 1

Author Comment

by:clintfield
ID: 22824060
The event log showed the same error after I published the release mode of the web project onto the staging server.
I dont think that the dll with the GenerateCommand would be causing issues since I actually use the same dll (dbreflection) on the same server in different apps.  It works there.  I also dont think I can get this recompiled since the original source code is lost somewhere.  But Ive been using it with success for so long, Im not sure why it would suddenly go "bad."
Maybe this issue is tougher than I thought.  I might need to adjust the points on this to 500.
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22830681
unfortunate that the original code has been lost; in that case I don't think you're going to get to the bottom of this.

basically, the code looks very much based on that in this MSDN artice:
http://msdn.microsoft.com/en-us/magazine/cc301780.aspx

but there are only 2 asserts mentioned in there:
check for SqlCommandMethod Attribute Missing
check for  mismatch in the count of parameters (excluding those marked with NonCommandParameterAttribute) declared on the method and the values sent to GenerateCommandParameters

And it looks like you've got them both covered. It seems that the developer in your company who used this MSDN code did the following:
1) added a further assert, unhelpfully with no "message" parameter passed (in my opinion, it is a greate shame that this is allowed).
2) copiled the code in "Dedug" mode
3) unhelpfully lost the code (then I am presuming left the company, right?)

I would advise going back to the original code provided from MSDN and compiling a new version for you to use just for this particlar application, but since the article was published in 2002 it seems MS have got rid of the download file. Perhaps MS could provide it if you contact them? the unfortunate outcome of this would be that you would lose any customisations done within your company.
0
 
LVL 1

Author Comment

by:clintfield
ID: 22830969
I think the code is based on that article.  I know the guy who wrote it and I may contact him to see if has had similar issues.  I guess Im really just confused on why it works in every other project I have and not this one.
Give me a day or so to see if I can get the original source and recompile in release mode.  If this can lead me to a solution or at least get me close, I will award points.  I think you are on the right track to the root of the problem...but the only way to tell is to try what you suggested.
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22831620
good, hope you can get hold of the code from him.
if you do get it, please could you post it here so we can take a look?
0
 
LVL 1

Author Comment

by:clintfield
ID: 22833987
I found the solution deep in a folder on my box!  It looks like it was compiled using debug.  The code snippet shows the generatecommand code.
		public static SqlCommand GenerateCommand(SqlConnection connection,
			MethodInfo method, object[] values)
		{
			if (method == null)
				method = (MethodInfo) (new StackTrace().GetFrame(1).GetMethod());
 
			//
			// Get the SqlCommandMethodAttribute on the method passed in.
			// This attribute is required in order to use the method for
			// generating a command object.
			//
 
			SqlCommandMethodAttribute commandAttribute = (SqlCommandMethodAttribute) Attribute.GetCustomAttribute(
				method, typeof(SqlCommandMethodAttribute));
 
			Debug.Assert(commandAttribute != null);
			Debug.Assert(commandAttribute.CommandType == CommandType.StoredProcedure ||
				commandAttribute.CommandType == CommandType.Text);
 
			//
			// Create a SqlCommand object and configure it according to the
			// specification of the attribute.
			//
 
			SqlCommand command = new SqlCommand();
			command.Connection = connection;
			command.CommandType = commandAttribute.CommandType;
 
			//
			// Get the text of the command. If it is zero-length then use 
			// the name of the method as a stored procedure name.
			//
 
			if (commandAttribute.CommandText.Length == 0)
			{
				Debug.Assert(commandAttribute.CommandType == CommandType.StoredProcedure);
				command.CommandText = method.Name;
			}
			else
			{
				command.CommandText = commandAttribute.CommandText;
			}
 
			//
			// Generate the command parameters, adding the return value.
			//
 
			GenerateCommandParameters(command, method, values);
			command.Parameters.Add(ReturnValueParameterName, SqlDbType.Int).Direction = ParameterDirection.ReturnValue;
 
			return command;
		}

Open in new window

0
 
LVL 1

Author Comment

by:clintfield
ID: 22834041
FYI:
I realized that the snippet above is actually from a solution that creates a form which will allow you to scan your database for sprocs and generate the code to use in your project.  So it is not the dll code, but an exe code.  Im assuming however that they both use the same GenerateCommand method.
 
0
 
LVL 1

Author Comment

by:clintfield
ID: 22839967
I tried an experiment that I hope may help.  I decided to publish the application to my local machine. So far, Ive only been running in debug mode and everything works fine.  
After publishing, I ran the application.  A box popped up (see the snippet) that looks like the event log error, and I choose ignore.  I then got the aspx error you see in the snippet below.
Does this help any?  At least it appears as though the issue occurs when I publish.  

---------------------------
Assertion Failed: Abort=Quit, Retry=Debug, Ignore=Continue
---------------------------
 
 
 
 
 
 
    at SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values)  
 
    at employees.GetActiveEmployees()  
 
    at addcase.Page_Load(Object sender, EventArgs e)  
 
    at CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)  
 
    at CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)  
 
    at Control.OnLoad(EventArgs e)  
 
    at ControlAdapter.OnLoad(EventArgs e)  
 
    at Control.LoadRecursive()  
 
    at Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
 
    at Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)  
 
    at Page.ProcessRequest()  
 
    at Page.ProcessRequestWithNoAssert(HttpContext context)  
 
    at Page.ProcessRequest(HttpContext context)  
 
    at addcase_aspx.ProcessRequest(HttpContext context)  
 
    at CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()  
 
    at HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)  
 
    at ApplicationStepManager.ResumeSteps(Exception error)  
 
    at HttpApplication.System.Web.IHttpAsyncHandler.BeginProcessRequest(HttpContext context, AsyncCallback cb, Object extraData)  
 
    at HttpRuntime.ProcessRequestInternal(HttpWorkerRequest wr)  
 
    at HttpRuntime.ProcessRequestNoDemand(HttpWorkerRequest wr)  
 
    at ISAPIRuntime.ProcessRequest(IntPtr ecb, Int32 iWRType)  
 
 
---------------------------
Abort   Retry   Ignore   
---------------------------
 
 
 
Object reference not set to an instance of an object. 
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
 
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
 
Source Error: 
 
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.  
 
Stack Trace: 
 
 
[NullReferenceException: Object reference not set to an instance of an object.]
   dbreflection.Data.Sql.SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values) +187
   employees.GetActiveEmployees() +241
   addcase.Page_Load(Object sender, EventArgs e) +93
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34
   System.Web.UI.Control.OnLoad(EventArgs e) +99
   System.Web.UI.Adapters.ControlAdapter.OnLoad(EventArgs e) +12
   System.Web.UI.Control.LoadRecursive() +2114793
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
 
 

Open in new window

0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22840508
gosh, it is the assert refrerred to in the article sorry; the one that checks for the SqlCommandMethod Attribute

why is it not pickick up this attribute???

hang on - have just noticed soemthing that has been staring us in the face all along -something is missing from your stack trace.
where it says:
    at SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values)  
    at employees.GetActiveEmployees()  
    at addcase.Page_Load(Object sender, EventArgs e)  

it appears wrong, as it says GenerateCommand is called directly from GetActiveEmployees - its not though is it, its called from procGetActiveEmployees
I would therefore expect the stack trace to be:

    at SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values)  
    at sprocs.procGetActiveEmployees(SqlConnection connection)
    at employees.GetActiveEmployees()  
    at addcase.Page_Load(Object sender, EventArgs e)  

this is causing your problem; when GenerateCommand pulls the method name from the stack, its getting the wrong method. Let me have a think about how this could be.

In the mean time, I think you could work around this by explicitly passing the current method:

 


    [SqlCommandMethod(CommandType.StoredProcedure)]
    public static SqlCommand procGetActiveEmployees(
     [NonCommandParameter] SqlConnection connection)
    {
        return SqlCommandGenerator.GenerateCommand(connection, System.Reflection.MethodInfo.GetCurrentMethod(), SqlCommandGenerator.NoValues);
    }

Open in new window

0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22840527
and there's nowhere in employees.GetActiveEmployees where SqlCommandGenerator.GenerateCommand is being called directly??
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22840590
if you could post the full code for SqlCommandGenerator, as well as SqlCommandMethodAttribute, SqlParameterAttribute, and NonCommandParameterAttribute, that would be great, thanks
0
 
LVL 1

Author Comment

by:clintfield
ID: 22840614

employees.GetActiveEmployees goes to this code:

con.Open();
SqlCommand cmd = new SqlCommand();
cmd = sprocs.procGetActiveEmployees(con);
SqlDataAdapter objDa = new SqlDataAdapter(cmd);
objDa.Fill(dtS);
objDa.Dispose();
 
sprocs.procGetActiveEmployees goes to this code:
 
[SqlCommandMethod(CommandType.StoredProcedure)]
public static SqlCommand procGetActiveEmployees(
[NonCommandParameter] SqlConnection connection)
{
return SqlCommandGenerator.GenerateCommand(connection, null, SqlCommandGenerator.NoValues);
}
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22840864
yes, I've got that, I was wondering about the code you found "deep in a folder"; does it include the full classes for
SqlCommandGenerator
SqlCommandMethodAttribute
SqlParameterAttribute
NonCommandParameterAttribute
?

please try the line below in your procGetActiveEmployees method:


return SqlCommandGenerator.GenerateCommand(connection, System.Reflection.MethodInfo.GetCurrentMethod(), SqlCommandGenerator.NoValues);
 
 

Open in new window

0
 
LVL 1

Author Comment

by:clintfield
ID: 22840941
Here is what I got when I tried to compile with the line you suggested above.
Error 1 The best overloaded method match for 'dbreflection.Data.Sql.SqlCommandGenerator.GenerateCommand(System.Data.SqlClient.SqlConnection, System.Reflection.MethodInfo, object[])' has some invalid arguments
 Error 2 Argument '2': cannot convert from 'System.Reflection.MethodBase' to 'System.Reflection.MethodInfo'

0
 
LVL 1

Author Comment

by:clintfield
ID: 22840999
Im not sure if this helps...but I checked the Application Log and the event there seems to give some more info.  See what you think.
Event code: 3005 
Event message: An unhandled exception has occurred. 
Event time: 10/30/2008 8:43:48 AM 
Event time (UTC): 10/30/2008 12:43:48 PM 
Event ID: a5daf40a79144e34bc39674ad734cdd9 
Event sequence: 25 
Event occurrence: 4 
Event detail code: 0 
 
Application information: 
    Application domain: /LM/W3SVC/1/Root/Outreach-1-128698423571714534 
    Trust level: Full 
    Application Virtual Path: /Outreach 
    Application Path: c:\inetpub\wwwroot\Outreach\ 
    Machine name: L01 
 
Process information: 
    Process ID: 4340 
    Process name: aspnet_wp.exe 
    Account name: L01\ASPNET 
 
Exception information: 
    Exception type: NullReferenceException 
    Exception message: Object reference not set to an instance of an object. 
 
Request information: 
    Request URL: http://l01/outreach/addcase.aspx 
    Request path: /outreach/addcase.aspx 
    User host address: xx.xxx.xx.xx 
    User:  
    Is authenticated: False 
    Authentication Type:  
    Thread account name: L01\ASPNET 
 
Thread information: 
    Thread ID: 1 
    Thread account name: L01\ASPNET 
    Is impersonating: False 
    Stack trace:    at dbreflection.Data.Sql.SqlCommandGenerator.GenerateCommand(SqlConnection connection, MethodInfo method, Object[] values)
   at employees.GetActiveEmployees()
   at addcase.Page_Load(Object sender, EventArgs e)
   at System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e)
   at System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e)
   at System.Web.UI.Control.OnLoad(EventArgs e)
   at System.Web.UI.Adapters.ControlAdapter.OnLoad(EventArgs e)
   at System.Web.UI.Control.LoadRecursive()
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
 
 
Custom event details: 
 
For more information, see Help and Support Center at 

Open in new window

0
 
LVL 8

Accepted Solution

by:
the_crazed earned 500 total points
ID: 22841229
sorry, my bad, use
return SqlCommandGenerator.GenerateCommand(connection, (System.Reflection.MethodInfo) System.Reflection.MethodInfo.GetCurrentMethod(), SqlCommandGenerator.NoValues);

Open in new window

0
 
LVL 1

Author Comment

by:clintfield
ID: 22841595
That line works!  What the heck is going on though?  Why do my other applications use the same dbreflection code and work...while this time it doesnt?  I actually created a small app with only one page that calls the getactiveemployees.  I got the same error.  I even tried a different db and method just to see if that made a difference.  
Im pretty satisfied with the solution...but knowing why some of my apps work with the same code still bugs me.  Any ideas?  Im going to do one more test on the original staging server, but it looks like you get the points for this.  Great job!
0
 
LVL 8

Expert Comment

by:the_crazed
ID: 22841665
the problem is that when you get to within GenerateCommand, its caller (procGetActiveEmployees) is not on the stack.

the cause.... now I've no idea about that.

I've tried to reproduce the issue in code here and connot; every time, the caller is on the stack.

I've never heard of this happening; I've Googled the symptom and come up with jack. If you can find anything, I'd love to hear it, please let me know.

if you can find it, I'd love to see the full code for the classes
SqlCommandGenerator
SqlCommandMethodAttribute
SqlParameterAttribute
NonCommandParameterAttribute


just in case there's anything odd going on in there
0
 
LVL 1

Author Comment

by:clintfield
ID: 22841842
The testing went well.  I think just replacing the 'null' parameter in that method with '
(System.Reflection.MethodInfo)System.Reflection.MethodInfo.GetCurrentMethod()' did the trick.
Im not sure if you looked at the original thread I listed in my question, but its very odd that when I first tried to debug on the staging server, the application actually worked for a short bit of time.  I never got the debugging to work correctly...and the application never worked again either.  Its just odd that it actually did work on the staging server for a brief period.  That really perplexes me....but Im not gonna lose sleep over it now that you have given me a good workaround.
My friend's PC just died, but he says he will get the code to me soon.  I will try to get it to you when he does.  
Thanks!
 
0
 
LVL 1

Author Closing Comment

by:clintfield
ID: 31509381
Great job.  Thanks for sticking with it.
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question