@@ -105,39 +105,39 @@ public static string Resolve(string library)
105105
106106 static IEnumerable < string > GetSearchLocations ( )
107107 {
108- string execPath = Path . GetDirectoryName ( Assembly . GetExecutingAssembly ( ) . Location ) ;
109- if ( execPath is not null )
108+ // AppContext.BaseDirectory is the recommended way to get the app directory,
109+ // especially for single-file apps where Assembly.Location returns empty.
110+ if ( ! string . IsNullOrEmpty ( AppContext . BaseDirectory ) )
110111 {
111- yield return execPath ;
112+ yield return AppContext . BaseDirectory ;
112113 }
113114
114- string callingPath = Path . GetDirectoryName ( Assembly . GetCallingAssembly ( ) . Location ) ;
115- if ( callingPath is not null )
115+ #pragma warning disable IL3000 // Assembly.Location returns empty in single-file apps (handled by AppContext.BaseDirectory above)
116+ string execPath = Assembly . GetExecutingAssembly ( ) ? . Location ;
117+ if ( ! string . IsNullOrEmpty ( execPath ) )
116118 {
117- yield return callingPath ;
119+ yield return Path . GetDirectoryName ( execPath ) ;
118120 }
119121
120- var entryAssembly = Assembly . GetEntryAssembly ( ) ;
121- if ( entryAssembly is not null )
122+ string callingPath = Assembly . GetCallingAssembly ( ) ? . Location ;
123+ if ( ! string . IsNullOrEmpty ( callingPath ) )
122124 {
123- string entryPath = Path . GetDirectoryName ( entryAssembly . Location ) ;
124- if ( entryPath is not null )
125- {
126- yield return entryPath ;
127- }
125+ yield return Path . GetDirectoryName ( callingPath ) ;
128126 }
129127
130- if ( AppContext . BaseDirectory is not null )
128+ var entryAssemblyPath = Assembly . GetEntryAssembly ( ) ? . Location ;
129+ if ( ! string . IsNullOrEmpty ( entryAssemblyPath ) )
131130 {
132- yield return AppContext . BaseDirectory ;
131+ yield return Path . GetDirectoryName ( entryAssemblyPath ) ;
133132 }
133+ #pragma warning restore IL3000
134134
135135 foreach ( string extraPath in ExtraNativeLibSearchPaths )
136136 {
137137 yield return extraPath ;
138138 }
139139
140- if ( execPath is not null )
140+ if ( ! string . IsNullOrEmpty ( execPath ) )
141141 {
142142 // If the this lib is being executed from its nuget package directory then the native
143143 // files should be found up a couple directories.
0 commit comments