Is SetDllImportResolver invoked multiple times normal? #86088
-
I'm working on bindings for Expat to implement my own XMPP library. Then i provide a way to set an environment variable to manually point to correct expat library. Everything is working as excepted, expat is begin called and parsing is working, but... I had placed an static nint TryResolveExpat(string name, Assembly assembly, DllImportSearchPath? searchPath = default)
{
if (name.Contains("libexpat", StringComparison.InvariantCultureIgnoreCase))
{
string libFile = Environment.GetEnvironmentVariable("EXPAT_LIBRARY_DIR");
// fallback to default dll importer
if (string.IsNullOrWhiteSpace(libFile))
return default;
// fallback to default dll importer
if (!File.Exists(libFile))
return default;
Debug.WriteLine("Expat DLL Import Resolved: " + libFile);
// attempt to load expat provided in env.
return NativeLibrary.Load(libFile, assembly, searchPath);
}
// fallback to default dll importer
return nint.Zero;
} And for my surprise is calling multiple times, my guess this is causing some memory leak loading many times into memory? Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Using libexpat v2.5.0!
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll The file in question 1st: Get expat version (then next line you can see the version) UPDATE: I've updated code to display address of returned Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Using libexpat v2.5.0!
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000)
Expat DLL Import Resolved: C:\vcpkg\installed\x64-windows\debug\bin\libexpatd.dll (at: 0000007FFC41FE0000) But still this normal calling multipletimes even the library was resolved once? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
@jkotas please have a look here. |
Beta Was this translation helpful? Give feedback.
-
Yes, this is expected. Runtime does not maintain caches of resolved native dll handles. |
Beta Was this translation helpful? Give feedback.
Yes, this is expected. Runtime does not maintain caches of resolved native dll handles.