jd78
12-19-2006, 02:47 PM
I am using the following advice to log method invocations.
public class LoggingBeforeAdvice : IMethodBeforeAdvice
{
private static ILog _log;
#region IMethodBeforeAdvice Members
public void Before(MethodInfo method, object[] args, object target)
{
if (_log == null)
_log = LogManager.GetLogger(method.DeclaringType);
string arguments = string.Empty;
if (args != null)
foreach (object arg in args)
{
try
{
arguments += arg.ToString() + ", ";
}
catch (Exception)
{}
}
_log.Info(method.Name + "Begin: " + arguments);
}
This works until I am passing variables by reference, at which point I get an error like the following:
System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This occurs at the line in the try/catch block. Crazy part is that the try/catch block above FAILS to catch this error. :confused: I was hoping I could just catch and ignore, but it seems not. Any thoughts? I am using Spring 1.0.2, with .net 2.0.
public class LoggingBeforeAdvice : IMethodBeforeAdvice
{
private static ILog _log;
#region IMethodBeforeAdvice Members
public void Before(MethodInfo method, object[] args, object target)
{
if (_log == null)
_log = LogManager.GetLogger(method.DeclaringType);
string arguments = string.Empty;
if (args != null)
foreach (object arg in args)
{
try
{
arguments += arg.ToString() + ", ";
}
catch (Exception)
{}
}
_log.Info(method.Name + "Begin: " + arguments);
}
This works until I am passing variables by reference, at which point I get an error like the following:
System.AccessViolationException : Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This occurs at the line in the try/catch block. Crazy part is that the try/catch block above FAILS to catch this error. :confused: I was hoping I could just catch and ignore, but it seems not. Any thoughts? I am using Spring 1.0.2, with .net 2.0.