1616namespace Smdn . Reflection . ReverseGenerating . ListApi ;
1717
1818internal sealed class PackageDependencyAssemblyResolver {
19- private static DependencyContext ? LoadDependencyContextIfDepsJsonExist ( string assemblyPath , ILogger ? logger = null )
19+ private static (
20+ DependencyContext ? DependencyContext ,
21+ string AssemblyDepsJsonPath
22+ )
23+ LoadDependencyContextIfDepsJsonExist ( string assemblyPath , ILogger ? logger = null )
2024 {
2125 if ( assemblyPath is null )
2226 throw new ArgumentNullException ( nameof ( assemblyPath ) ) ;
@@ -25,23 +29,38 @@ internal sealed class PackageDependencyAssemblyResolver {
2529
2630 var assemblyDepsJsonPath = Path . ChangeExtension ( assemblyPath , ".deps.json" ) ;
2731
28- if ( ! File . Exists ( assemblyDepsJsonPath ) ) {
29- logger ? . LogWarning ( "dependency configuration file not found: '{AssemblyDepsJsonPath}'" , assemblyDepsJsonPath ) ;
30- return null ;
32+ if ( File . Exists ( assemblyDepsJsonPath ) ) {
33+ logger ? . LogDebug ( "dependency configuration file found: '{AssemblyDepsJsonPath}'" , assemblyDepsJsonPath ) ;
34+ }
35+ else {
36+ logger ? . LogDebug ( "dependency configuration file could not be found: '{AssemblyDepsJsonPath}'" , assemblyDepsJsonPath ) ;
37+
38+ return ( null , assemblyDepsJsonPath ) ;
3139 }
3240
3341 using var stream = File . OpenRead ( assemblyDepsJsonPath ) ;
3442 using var reader = new DependencyContextJsonReader ( ) ;
3543
36- return reader . Read ( stream ) ;
44+ try {
45+ var context = reader . Read ( stream ) ;
46+
47+ logger ? . LogDebug ( "dependency configuration file loaded: '{AssemblyDepsJsonPath}'" , assemblyDepsJsonPath ) ;
48+
49+ return ( context , assemblyDepsJsonPath ) ;
50+ }
51+ catch ( Exception ex ) {
52+ logger ? . LogError ( ex , "dependency configuration file could not be loaded: '{AssemblyDepsJsonPath}'" , assemblyDepsJsonPath ) ;
53+
54+ return ( null , assemblyDepsJsonPath ) ;
55+ }
3756 }
3857
3958 public DependencyContext ? DependencyContext { get ; }
4059 private readonly ILogger ? logger ;
4160
4261 public PackageDependencyAssemblyResolver ( string componentAssemblyPath , ILogger ? logger = null )
4362 {
44- this . DependencyContext = LoadDependencyContextIfDepsJsonExist ( componentAssemblyPath , logger ) ;
63+ ( this . DependencyContext , _ ) = LoadDependencyContextIfDepsJsonExist ( componentAssemblyPath , logger ) ;
4564 this . logger = logger ;
4665 }
4766
0 commit comments