From bef06639a2ed6d641792fa5ee781ae85d48348cf Mon Sep 17 00:00:00 2001 From: Scott Jones Date: Fri, 29 May 2020 09:37:24 -0700 Subject: [PATCH] Add RID-specific runtime folder load fallback (#291) --- cswinrt/strings/WinRT.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/cswinrt/strings/WinRT.cs b/cswinrt/strings/WinRT.cs index 154345ee2..ac7f2ff91 100644 --- a/cswinrt/strings/WinRT.cs +++ b/cswinrt/strings/WinRT.cs @@ -132,6 +132,17 @@ public static DllModule Load(string fileName) // Explicitly look for module in the same directory as this one, and // use altered search path to ensure any dependencies in the same directory are found. _moduleHandle = Platform.LoadLibraryExW(System.IO.Path.Combine(_currentModuleDirectory, fileName), IntPtr.Zero, /* LOAD_WITH_ALTERED_SEARCH_PATH */ 8); +#if !NETSTANDARD2_0 + if (_moduleHandle == IntPtr.Zero) + { + try + { + // Allow runtime to find module in RID-specific relative subfolder + _moduleHandle = NativeLibrary.Load(fileName, Assembly.GetExecutingAssembly(), null); + } + catch (Exception) { } + } +#endif if (_moduleHandle == IntPtr.Zero) { Marshal.ThrowExceptionForHR(Marshal.GetHRForLastWin32Error());