Strange behavior in Release mode vs. Debug mode

  • Thread starter Thread starter Jón Óskar Erlendsson
  • Start date Start date
J

Jón Óskar Erlendsson

hi there,

I got a rather annoying functionality in my code that I could not figure
out.
My system is built with a "operation based" functionality which means that
a user's permission is based on which stored procedures he/she can execute
through the program.
When I ran it in debug mode ( either F5 or CTRL+F5) the code worked fine,
but when it came to running it in release mode an unexptected behavior was
presented.

let me show you the code:

public void DeleteFFN( int contactId, int airlineId,
IM.Windows.Helper.User user )
{
this.sprocName = "DeleteFFN_sp";

if( user.SystemSproc.ContainsKey(this.sprocName) ) // SystemSproc is a
hashtable
{
try
{
int numRows = SqlHelper.ExecuteNonQuery( this.connectionString,
this.sprocName, new Object[]{contactId, airlineId} );
}
catch( System.InvalidOperationException ex )
{
throw new
IM.Exception.IMGenericException(this.genericExceptionMessage, ex);
}
catch( System.Data.SqlClient.SqlException ex )
{
throw new
IM.Exception.IMGenericException(this.genericExceptionMessage, ex);
}
/* NOTE THIS EMPTY FINALLY BLOCK: */
finally
{
}
}
else
{
throw new
IM.Exception.ExecutePermissionDeniedException(this.executeDeniedMessage,
sprocName, user.UserName);
}
}

in release mode the exception in the else statement was thrown, but the code
in the if statement executed successfully.
when I removed the empty finally clause, the exception was not thrown.
why this occurs I do not know but I it would be greatly appreciated if
someone could explain this to me...

kind regards,
jon oskar erlendsson MCP
Information Management, Iceland
 
in release mode the exception in the else statement was thrown, but the code
in the if statement executed successfully.
when I removed the empty finally clause, the exception was not thrown.
why this occurs I do not know but I it would be greatly appreciated if
someone could explain this to me...

Could you try to come up with a short but complete example which
doesn't rely on all your other code? See
http://www.pobox.com/~skeet/csharp/complete.html for what I mean. Also,
which version of VS.NET are you using?
 
This is a bug in the C# compiler. See:
http://www.jelovic.com/weblog/e49.htm

The above Web page makes it sound like this bug always occurs, but you
say it only happens in release mode? Interesting. Can you check your
build options, and see if the optimization settings are different
between debug and release?
 
Oh, and BTW, the bug registry seems to claim that this bug was fixed in
the 1.1 Framework. What version of VS are you using?


Joe said:
This is a bug in the C# compiler. See:
http://www.jelovic.com/weblog/e49.htm

The above Web page makes it sound like this bug always occurs, but you
say it only happens in release mode? Interesting. Can you check your
build options, and see if the optimization settings are different
between debug and release?


Jón Óskar Erlendsson said:
hi there,

I got a rather annoying functionality in my code that I could not figure
out.
My system is built with a "operation based" functionality which means
that
a user's permission is based on which stored procedures he/she can
execute
through the program.
When I ran it in debug mode ( either F5 or CTRL+F5) the code worked fine,
but when it came to running it in release mode an unexptected behavior
was
presented.

let me show you the code:

public void DeleteFFN( int contactId, int airlineId,
IM.Windows.Helper.User user )
{
this.sprocName = "DeleteFFN_sp";

if( user.SystemSproc.ContainsKey(this.sprocName) ) //
SystemSproc is a
hashtable
{
try
{
int numRows = SqlHelper.ExecuteNonQuery( this.connectionString,
this.sprocName, new Object[]{contactId, airlineId} );
}
catch( System.InvalidOperationException ex )
{
throw new
IM.Exception.IMGenericException(this.genericExceptionMessage, ex);
}
catch( System.Data.SqlClient.SqlException ex )
{
throw new
IM.Exception.IMGenericException(this.genericExceptionMessage, ex);
}
/* NOTE THIS EMPTY FINALLY BLOCK: */
finally
{
}
}
else
{
throw new
IM.Exception.ExecutePermissionDeniedException(this.executeDeniedMessage,
sprocName, user.UserName);
}
}

in release mode the exception in the else statement was thrown, but
the code
in the if statement executed successfully.
when I removed the empty finally clause, the exception was not thrown.
why this occurs I do not know but I it would be greatly appreciated if
someone could explain this to me...

kind regards,
jon oskar erlendsson MCP
Information Management, Iceland
 
Back
Top