Tag: targetinvocationexception

尝试从SSIS包保存大于~1.5 MiB的文件时,EPPlus 2.9.0.1抛出System.IO.IsolatedStorage.IsolatedStorageException

问题 当我尝试使用EPPlus保存文件超过~1.5 MiB时ExcelPackage.Save()抛出System.IO.IsolatedStorage.IsolatedStorageException 。 说明 我正在使用Visual Studio 2008 9.0.30729.4462 QFE和.NET Framework 3.5 SP1创建一个SSIS包,以通过EPPlus 2.9.0.1库导出SQL Server 2008 SP2 10.0.4311.0 64 bit表的EPPlus 2.9.0.1 。 SSIS包非常简单:一个Execute SQL Task ,它读取表的内容并将其放入一个变量后跟一个Script task ,该Script task读取记录集变量并通过EPPlus将内容保存到磁盘。 脚本任务的代码是: namespace ST_00a0b40814db4c7290b71f20a45b62c6.csproj { using System; using System.AddIn; using System.Data; using System.Data.OleDb; using System.IO; using Microsoft.SqlServer.Dts.Runtime; using Microsoft.SqlServer.Dts.Tasks.ScriptTask; using OfficeOpenXml; [AddIn(“ScriptMain”, Version = “1.0”, Publisher = […]

如何在不丢失堆栈跟踪的情况下重新抛出TargetInvocationException的内部exception

我有许多使用Delegate.DynamicInvoke调用的方法。 其中一些方法进行数据库调用,我希望能够捕获TargetInvocationException并且不捕获TargetInvocationException并通过其内部搜索来查找实际出错的地方。 我正在使用此方法重新抛出,但它清除了堆栈跟踪: try { return myDelegate.DynamicInvoke(args); } catch(TargetInvocationException ex) { Func getInner = null; getInner = delegate(TargetInvocationException e) { if (e.InnerException is TargetInvocationException) return getInner((TargetInvocationException) e.InnerException); return e.InnerException; }; Exception inner = getInner(ex); inner.PreserveStackTrace(); throw inner; } PreserveStackTrace方法是我修复的扩展方法,感谢另一篇文章(我不知道它实际上做了什么)。 但是,这似乎不会保留跟踪: public static void PreserveStackTrace(this Exception e) { var ctx = new StreamingContext(StreamingContextStates.CrossAppDomain); var mgr = […]

为什么IDE会将TargetInvocationException视为未捕获?

我有一些代码使用reflection来从对象中提取属性值。 在某些情况下,属性可能会抛出exception,因为它们具有空引用等。 object result; try { result = propertyInfo.GetValue(target, null); } catch (TargetInvocationException ex) { result = ex.InnerException.Message; } catch (Exception ex) { result = ex.Message; } 最终代码正常工作,但是当我在调试器下运行时: 当属性抛出exception时,IDE将进入调试器,就好像exception未被捕获一样。 如果我刚刚运行,程序就会流出,exception作为TargetInvocationException出现,并在InnerException属性中有真正的exception。 我怎么能阻止这种情况发生?