This line of code causes the exceptions shown below:
object arg = methodCallMessage.Args[i];
private static List<ParameterInformation> GetParameterInfoList( IMethodCallMessage methodCallMessage )
{
List<ParameterInformation> parameterInformationList = new List<ParameterInformation>();
// Note: This works even if a parameter's value is null.
for( int i = 0 ; i < methodCallMessage.ArgCount ; i++ )
{
string argName = methodCallMessage.GetArgName(i);
object arg = methodCallMessage.Args[i];
var parameterInformation = new ParameterInformation(argName, arg);
parameterInformationList.Add(parameterInformation);
}
return parameterInformationList;
}
Exception: FatalExecutionEngineError: The runtime has encountered a fatal error. The address of the error was at 0x71b97e8d, on thread 0x2ef4. The error code is 0xc0000005. This error may be a bug in the CLR or in the unsafe or non-verifiable portions of user code. Common sources of this bug include user marshaling errors for COM-interop or PInvoke, which may corrupt the stack.
Or sometimes this exception:
AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
This happens on more than one machine.
In the call stack, when I show external code, this is at the top: mscorlib.dll!System.Runtime.Remoting.Messaging.Message.Args.get() + 0x5 bytes.
Any ideas why this is happening, or how to fix it?
Note: The code that calls this method has a lock placed around it, so it shouldn't be a threading/timing issue.
This is more of a work-around than an actual fix, but it works for this situation. The problem only occurs when being done in an async way. The code that started the process had this wrapped around it:
Task.Factory.StartNew(() =>
When I removed that, and just processed things synchronously, the problem went away.