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)
615
615
#if NET462
616
616
private static void LoadNetFrameworkDelegates ( string userSpecifiedPath )
617
617
{
618
- string path = userSpecifiedPath ;
618
+ var path = userSpecifiedPath ;
619
+ var loadLibraryFlags = WindowsNative . LoadLibraryFlags . LOAD_WITH_ALTERED_SEARCH_PATH ;
620
+
619
621
if ( path == null )
620
622
{
621
623
// 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)
652
654
{
653
655
path = Path . Combine ( baseDirectory , "librdkafka.dll" ) ;
654
656
}
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
+ }
655
665
}
656
666
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 )
658
668
{
659
669
// catch the last win32 error by default and keep the associated default message
660
670
var win32Exception = new Win32Exception ( ) ;
You can’t perform that action at this time.
0 commit comments