将本地语言exception转换为英语exception,包括英语堆栈跟踪

Currentlly我正在使用这种方法将exception转换为将原始exception消息转换为英语的exception:

C#:

[DebuggerStepThrough()] [Extension()] public Exception ToEnglish(T ex) where T : Exception { CultureInfo oldCI = Thread.CurrentThread.CurrentUICulture; Exception exEng = default(Exception); Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US"); // Instance Exception one time to retrieve an English message. exEng = (Exception)Activator.CreateInstance(ex.GetType); // Instance Exception a second time to pass additional parameters to its constructor. exEng = (Exception)Activator.CreateInstance(ex.GetType, new object[] { exEng.Message, ex }); Thread.CurrentThread.CurrentUICulture = oldCI; return exEng; } //======================================================= //Service provided by Telerik (www.telerik.com) //Conversion powered by NRefactory. //======================================================= 

Vb.Net:

   Public Function ToEnglish(Of T As Exception)(ByVal ex As T) As Exception Dim oldCI As CultureInfo = Thread.CurrentThread.CurrentUICulture Dim exEng As Exception Thread.CurrentThread.CurrentUICulture = CultureInfo.GetCultureInfo("en-US") ' Instance Exception one time to retrieve an English message. exEng = DirectCast(Activator.CreateInstance(ex.[GetType]), Exception) ' Instance Exception a second time to pass additional parameters to its constructor. exEng = DirectCast(Activator.CreateInstance(ex.[GetType], New Object() {exEng.Message, ex}), Exception) Thread.CurrentThread.CurrentUICulture = oldCI Return exEng End Function 

(我知道有些exception消息只是用英语部分定义)

但是,我对结果并不完全满意,因为我首先没有返回相同的运行时类型,而且结果exception的堆栈跟踪是空的,所以我需要保留原始exception的信息。生成的exception的InnerException属性。

然后,我想改进function,以满足那里的requeriments:

    1. 返回传递给type-parameter的相同Type的exception(例如FileNotFoundException )。
    1. 在生成的exception中,使用英语重新创建/保留stack-trace(和TargetSite属性)。

我不确定第2点是否可以实现,因为可能的堆栈限制?,无论如何我要知道,我怎么能做这两件事?