System.Exception.GetObjectData C# (CSharp) Method

GetObjectData() private method

private GetObjectData ( SerializationInfo info, StreamingContext context ) : void
info SerializationInfo
context StreamingContext
return void
        public virtual void GetObjectData(SerializationInfo info, StreamingContext context) 
        {
            String tempStackTraceString = _stackTraceString;
        
            if (info==null) 
            {
                throw new ArgumentNullException("info");
            }
            if (_className==null) 
            {
                _className=GetClassName();
            }
    
            if (_stackTrace!=null) 
            {
                if (tempStackTraceString==null) 
                {
                    tempStackTraceString = Environment.GetStackTrace(this, true);
                }
                if (_exceptionMethod==null) 
                {
                    RuntimeMethodHandle method = InternalGetMethod(_stackTrace).GetTypicalMethodDefinition();
                    _exceptionMethod = RuntimeType.GetMethodBase(method);
                }
            }

            if (_source == null) 
            {
                _source = Source; // Set the Source information correctly before serialization
            }
    
            info.AddValue("ClassName", _className, typeof(String));
            info.AddValue("Message", _message, typeof(String));
            info.AddValue("Data", _data, typeof(IDictionary));
            info.AddValue("InnerException", _innerException, typeof(Exception));
            info.AddValue("HelpURL", _helpURL, typeof(String));
            info.AddValue("StackTraceString", tempStackTraceString, typeof(String));
            info.AddValue("RemoteStackTraceString", _remoteStackTraceString, typeof(String));
            info.AddValue("RemoteStackIndex", _remoteStackIndex, typeof(Int32));
            info.AddValue("ExceptionMethod", GetExceptionMethodString(), typeof(String));
            info.AddValue("HResult", HResult);
            info.AddValue("Source", _source, typeof(String));
        }

Usage Example

        private void PreserveStackTrace(Exception exception)
        {
            var context = new StreamingContext(StreamingContextStates.CrossAppDomain);
            var serializationInfo = new SerializationInfo(typeof(Exception), new FormatterConverter());
            var constructor = typeof(Exception).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(SerializationInfo), typeof(StreamingContext) }, null);

            exception.GetObjectData(serializationInfo, context);
            constructor.Invoke(exception, new object[] { serializationInfo, context });
        }
All Usage Examples Of System.Exception::GetObjectData