22using System . Collections . Generic ;
33using System . IO ;
44using System . Linq ;
5- using System . Reflection ;
65using System . Threading . Tasks ;
76using Elasticsearch . Net ;
87using Elasticsearch . Net . Connection ;
@@ -126,21 +125,6 @@ Func<D, D> selector
126125 return this . DispatchAsync < D , Q , R , I > ( descriptor , dispatch ) ;
127126 }
128127
129- private static readonly Lazy < MethodInfo > preserveStackTraceMethodInfo = new Lazy < MethodInfo > ( ( ) =>
130- typeof ( Exception ) . GetMethod ( "InternalPreserveStackTrace" , BindingFlags . Instance | BindingFlags . NonPublic )
131- ) ;
132-
133- private static void RethrowKeepingStackTrace ( Exception exception )
134- {
135- // In .Net 4.5 it would be simple : ExceptionDispatchInfo.Capture(exception).Throw();
136- // But as NEST target .Net 4.0 the old internal method must be used
137- if ( preserveStackTraceMethodInfo . Value != null )
138- {
139- preserveStackTraceMethodInfo . Value . Invoke ( exception , null ) ;
140- }
141- throw exception ;
142- }
143-
144128 private Task < I > DispatchAsync < D , Q , R , I > (
145129 D descriptor
146130 , Func < ElasticsearchPathInfo < Q > , D , Task < ElasticsearchResponse < R > > > dispatch
@@ -158,13 +142,13 @@ D descriptor
158142 {
159143 var mr = r . Exception . InnerException as MaxRetryException ;
160144 if ( mr != null )
161- RethrowKeepingStackTrace ( mr ) ;
145+ mr . RethrowKeepingStackTrace ( ) ;
162146
163147 var ae = r . Exception . Flatten ( ) ;
164148 if ( ae . InnerException != null )
165- RethrowKeepingStackTrace ( ae . InnerException ) ;
149+ ae . InnerException . RethrowKeepingStackTrace ( ) ;
166150
167- RethrowKeepingStackTrace ( ae ) ;
151+ ae . RethrowKeepingStackTrace ( ) ;
168152 }
169153 return ResultsSelector < D , Q , R > ( r . Result , descriptor ) ;
170154 } ) ;
0 commit comments