11using System ;
22using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
33using Microsoft . VisualStudio . TestPlatform . ObjectModel . Navigation ;
4+ using Xunit . Abstractions ;
5+ using Xunit . Internal ;
46
57namespace Xunit . Runner . VisualStudio . Utility ;
68
@@ -13,38 +15,65 @@ class DiaSessionWrapper : IDisposable
1315 readonly AppDomainManager ? appDomainManager ;
1416#endif
1517 readonly DiaSessionWrapperHelper ? helper ;
16- readonly DiaSession session ;
18+ readonly DiaSession ? session ;
19+ readonly DiagnosticMessageSink diagnosticMessageSink ;
1720
18- public DiaSessionWrapper ( string assemblyFileName )
21+ public DiaSessionWrapper (
22+ string assemblyFileName ,
23+ DiagnosticMessageSink diagnosticMessageSink )
1924 {
20- session = new DiaSession ( assemblyFileName ) ;
25+ this . diagnosticMessageSink = Guard . ArgumentNotNull ( diagnosticMessageSink ) ;
2126
22- #if NETFRAMEWORK
23- var adapterFileName = typeof ( DiaSessionWrapperHelper ) . Assembly . GetLocalCodeBase ( ) ;
24- if ( adapterFileName is not null )
27+ try
28+ {
29+ session = new DiaSession ( assemblyFileName ) ;
30+ }
31+ catch ( Exception ex )
2532 {
26- appDomainManager = new AppDomainManager ( assemblyFileName ) ;
27- helper = appDomainManager . CreateObject < DiaSessionWrapperHelper > ( typeof ( DiaSessionWrapperHelper ) . Assembly . GetName ( ) , typeof ( DiaSessionWrapperHelper ) . FullName ! , adapterFileName ) ;
33+ diagnosticMessageSink . OnMessage ( new DiagnosticMessage ( $ "Exception creating DiaSession: { ex } ") ) ;
2834 }
35+
36+ try
37+ {
38+ #if NETFRAMEWORK
39+ var adapterFileName = typeof ( DiaSessionWrapperHelper ) . Assembly . GetLocalCodeBase ( ) ;
40+ if ( adapterFileName is not null )
41+ {
42+ appDomainManager = new AppDomainManager ( assemblyFileName ) ;
43+ helper = appDomainManager . CreateObject < DiaSessionWrapperHelper > ( typeof ( DiaSessionWrapperHelper ) . Assembly . GetName ( ) , typeof ( DiaSessionWrapperHelper ) . FullName ! , adapterFileName ) ;
44+ }
2945#else
30- helper = new DiaSessionWrapperHelper ( assemblyFileName ) ;
46+ helper = new DiaSessionWrapperHelper ( assemblyFileName ) ;
3147#endif
48+ }
49+ catch ( Exception ex )
50+ {
51+ diagnosticMessageSink . OnMessage ( new DiagnosticMessage ( $ "Exception creating DiaSessionWrapperHelper: { ex } ") ) ;
52+ }
3253 }
3354
3455 public INavigationData ? GetNavigationData (
3556 string typeName ,
3657 string methodName )
3758 {
38- if ( helper is null )
59+ if ( session is null || helper is null )
3960 return null ;
4061
41- helper . Normalize ( ref typeName , ref methodName ) ;
42- return session . GetNavigationDataForMethod ( typeName , methodName ) ;
62+ try
63+ {
64+ helper . Normalize ( ref typeName , ref methodName ) ;
65+ return session . GetNavigationDataForMethod ( typeName , methodName ) ;
66+ }
67+ catch ( Exception ex )
68+ {
69+ diagnosticMessageSink . OnMessage ( new DiagnosticMessage ( $ "Exception getting source mapping for { typeName } .{ methodName } : { ex } ") ) ;
70+ return null ;
71+ }
4372 }
4473
4574 public void Dispose ( )
4675 {
47- session . Dispose ( ) ;
76+ session ? . Dispose ( ) ;
4877#if NETFRAMEWORK
4978 appDomainManager ? . Dispose ( ) ;
5079#endif
0 commit comments