File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -615,7 +615,9 @@ public static bool Initialize(string userSpecifiedPath)
615615#if NET462
616616 private static void LoadNetFrameworkDelegates ( string userSpecifiedPath )
617617 {
618- string path = userSpecifiedPath ;
618+ var path = userSpecifiedPath ;
619+ var loadLibraryFlags = WindowsNative . LoadLibraryFlags . LOAD_WITH_ALTERED_SEARCH_PATH ;
620+
619621 if ( path == null )
620622 {
621623 // in net45, librdkafka.dll is not in the process directory, we have to load it manually
@@ -652,9 +654,17 @@ private static void LoadNetFrameworkDelegates(string userSpecifiedPath)
652654 {
653655 path = Path . Combine ( baseDirectory , "librdkafka.dll" ) ;
654656 }
657+
658+ if ( ! File . Exists ( path ) )
659+ {
660+ // Allow LoadLibrary to search for the dll using the default Windows search path as defined here:
661+ // https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#search-order-for-unpackaged-apps
662+ path = "librdkafka.dll" ;
663+ loadLibraryFlags = 0 ;
664+ }
655665 }
656666
657- if ( WindowsNative . LoadLibraryEx ( path , IntPtr . Zero , WindowsNative . LoadLibraryFlags . LOAD_WITH_ALTERED_SEARCH_PATH ) == IntPtr . Zero )
667+ if ( WindowsNative . LoadLibraryEx ( path , IntPtr . Zero , loadLibraryFlags ) == IntPtr . Zero )
658668 {
659669 // catch the last win32 error by default and keep the associated default message
660670 var win32Exception = new Win32Exception ( ) ;
You can’t perform that action at this time.
0 commit comments