diff --git a/src/NTwain/Internals/ExceptionExtensions.cs b/src/NTwain/Internals/ExceptionExtensions.cs index f186b38..0fe6548 100644 --- a/src/NTwain/Internals/ExceptionExtensions.cs +++ b/src/NTwain/Internals/ExceptionExtensions.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Reflection; +using System.Runtime.ExceptionServices; using System.Text; using System.Threading.Tasks; @@ -18,9 +19,13 @@ namespace NTwain.Internals { if (ex != null) { +#if NET40 typeof(Exception).GetMethod("PrepForRemoting", BindingFlags.NonPublic | BindingFlags.Instance)?.Invoke(ex, new object[0]); throw ex; +#else + ExceptionDispatchInfo.Capture(ex).Throw(); +#endif } }