1
1
using System ;
2
2
using Microsoft . VisualStudio . TestPlatform . ObjectModel ;
3
3
using Microsoft . VisualStudio . TestPlatform . ObjectModel . Navigation ;
4
+ using Xunit . Abstractions ;
5
+ using Xunit . Internal ;
4
6
5
7
namespace Xunit . Runner . VisualStudio . Utility ;
6
8
@@ -13,38 +15,65 @@ class DiaSessionWrapper : IDisposable
13
15
readonly AppDomainManager ? appDomainManager ;
14
16
#endif
15
17
readonly DiaSessionWrapperHelper ? helper ;
16
- readonly DiaSession session ;
18
+ readonly DiaSession ? session ;
19
+ readonly DiagnosticMessageSink diagnosticMessageSink ;
17
20
18
- public DiaSessionWrapper ( string assemblyFileName )
21
+ public DiaSessionWrapper (
22
+ string assemblyFileName ,
23
+ DiagnosticMessageSink diagnosticMessageSink )
19
24
{
20
- session = new DiaSession ( assemblyFileName ) ;
25
+ this . diagnosticMessageSink = Guard . ArgumentNotNull ( diagnosticMessageSink ) ;
21
26
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 )
25
32
{
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 } ") ) ;
28
34
}
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
+ }
29
45
#else
30
- helper = new DiaSessionWrapperHelper ( assemblyFileName ) ;
46
+ helper = new DiaSessionWrapperHelper ( assemblyFileName ) ;
31
47
#endif
48
+ }
49
+ catch ( Exception ex )
50
+ {
51
+ diagnosticMessageSink . OnMessage ( new DiagnosticMessage ( $ "Exception creating DiaSessionWrapperHelper: { ex } ") ) ;
52
+ }
32
53
}
33
54
34
55
public INavigationData ? GetNavigationData (
35
56
string typeName ,
36
57
string methodName )
37
58
{
38
- if ( helper is null )
59
+ if ( session is null || helper is null )
39
60
return null ;
40
61
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
+ }
43
72
}
44
73
45
74
public void Dispose ( )
46
75
{
47
- session . Dispose ( ) ;
76
+ session ? . Dispose ( ) ;
48
77
#if NETFRAMEWORK
49
78
appDomainManager ? . Dispose ( ) ;
50
79
#endif
0 commit comments