@@ -12,6 +12,13 @@ internal static class ProjectProcessEvidence
1212 private const string WorkDirectoryProperty = "executable.workdir" ;
1313 private const string AssemblySuffix = ".dll" ;
1414 private const string SymbolsSuffix = ".pdb" ;
15+ private const string ExecutableUnavailable = "The native executable is unavailable." ;
16+ private const string EntryAssemblyUnavailable = "The managed entry assembly is unavailable." ;
17+ private const string ProcessChanged = "The native process changed during evidence capture." ;
18+ private const string EvidenceMismatch = "The native process or its compiled files differ from the observed identity." ;
19+ private const string AmbiguousEntryAssembly = "The native project launch does not identify exactly one managed entry assembly." ;
20+ private const int SingleEntryAssembly = 1 ;
21+ private const int NoExplicitEntryAssembly = 0 ;
1522
1623 internal static NativeProcessEvidence Read ( ResourceNotificationService notifications , string resourceName )
1724 {
@@ -21,14 +28,14 @@ internal static NativeProcessEvidence Read(ResourceNotificationService notificat
2128 throw new InvalidOperationException ( ProcessFaultCommandProtocol . Refused ) ;
2229 }
2330 using var process = Process . GetProcessById ( identity . ProcessId ) ;
24- var executable = process . MainModule ? . FileName ?? throw new InvalidOperationException ( "The native executable is unavailable." ) ;
31+ var executable = process . MainModule ? . FileName ?? throw new InvalidOperationException ( ExecutableUnavailable ) ;
2532 var directory = ( string ) current . Snapshot . Properties . Single ( property => property . Name == WorkDirectoryProperty ) . Value ! ;
2633 var arguments = ( IEnumerable < string > ) current . Snapshot . Properties . Single ( property => property . Name == ArgumentsProperty ) . Value ! ;
2734 var managed = ResolveAssembly ( project . GetProjectMetadata ( ) . ProjectPath , executable , directory , arguments ) ;
2835 var binary = CaptureBinary ( executable , managed ) ;
2936 if ( ProjectProcessIdentity . Read ( notifications , resourceName ) != identity )
3037 {
31- throw new InvalidOperationException ( "The native process changed during evidence capture." ) ;
38+ throw new InvalidOperationException ( ProcessChanged ) ;
3239 }
3340 return new ( resourceName , identity . ProcessId , new DateTime ( identity . ProcessStartTimeUtcTicks , DateTimeKind . Utc ) ,
3441 new DateTime ( identity . AspireStartTimeUtcTicks , DateTimeKind . Utc ) , binary ) ;
@@ -37,8 +44,8 @@ internal static NativeProcessEvidence Read(ResourceNotificationService notificat
3744 internal static NativeProcessEvidence ReadCurrent ( string name )
3845 {
3946 using var process = Process . GetCurrentProcess ( ) ;
40- var executable = process . MainModule ? . FileName ?? throw new InvalidOperationException ( "The native executable is unavailable." ) ;
41- var assembly = Assembly . GetEntryAssembly ( ) ? . Location ?? throw new InvalidOperationException ( "The managed entry assembly is unavailable." ) ;
47+ var executable = process . MainModule ? . FileName ?? throw new InvalidOperationException ( ExecutableUnavailable ) ;
48+ var assembly = Assembly . GetEntryAssembly ( ) ? . Location ?? throw new InvalidOperationException ( EntryAssemblyUnavailable ) ;
4249 return new ( name , process . Id , process . StartTime . ToUniversalTime ( ) , null , CaptureBinary ( executable , assembly ) ) ;
4350 }
4451
@@ -51,7 +58,7 @@ internal static void Verify(NativeProcessEvidence expected)
5158 || executable != expected . Binary . ExecutablePath
5259 || CaptureBinary ( executable , expected . Binary . AssemblyPath ) != expected . Binary )
5360 {
54- throw new InvalidDataException ( "The native process or its compiled files differ from the observed identity." ) ;
61+ throw new InvalidDataException ( EvidenceMismatch ) ;
5562 }
5663 }
5764
@@ -61,15 +68,15 @@ private static string ResolveAssembly(string project, string executable, string
6168 var expected = name + AssemblySuffix ;
6269 var explicitPaths = arguments . Where ( argument => Path . GetFileName ( argument ) == expected )
6370 . Select ( argument => Path . GetFullPath ( argument , directory ) ) . Distinct ( StringComparer . Ordinal ) . ToArray ( ) ;
64- if ( explicitPaths . Length == 1 )
71+ if ( explicitPaths . Length == SingleEntryAssembly )
6572 {
6673 return explicitPaths . Single ( ) ;
6774 }
68- if ( Path . GetFileNameWithoutExtension ( executable ) == name && explicitPaths . Length == 0 )
75+ if ( Path . GetFileNameWithoutExtension ( executable ) == name && explicitPaths . Length == NoExplicitEntryAssembly )
6976 {
7077 return Path . ChangeExtension ( executable , AssemblySuffix ) ;
7178 }
72- throw new InvalidOperationException ( "The native project launch does not identify exactly one managed entry assembly." ) ;
79+ throw new InvalidOperationException ( AmbiguousEntryAssembly ) ;
7380 }
7481
7582 private static NativeBinaryEvidence CaptureBinary ( string executable , string assembly )
0 commit comments