diff --git a/NuGet.config b/NuGet.config
index 4c76f3d8269f6a..ebfb913af2fa11 100644
--- a/NuGet.config
+++ b/NuGet.config
@@ -9,7 +9,7 @@
-
+
diff --git a/eng/Version.Details.xml b/eng/Version.Details.xml
index 0df6498d29d213..3a7ae0e0f81b10 100644
--- a/eng/Version.Details.xml
+++ b/eng/Version.Details.xml
@@ -10,15 +10,15 @@
https://github.com/dotnet/emsdk
- 3c730c2c99c521adabe9b67b74bdba3a682d66d7
+ 275d1fa1fa5df44c2189d3976a351ed001e6f7b4
https://github.com/dotnet/emsdk
- 3c730c2c99c521adabe9b67b74bdba3a682d66d7
+ 275d1fa1fa5df44c2189d3976a351ed001e6f7b4
https://github.com/dotnet/emsdk
- 3c730c2c99c521adabe9b67b74bdba3a682d66d7
+ 275d1fa1fa5df44c2189d3976a351ed001e6f7b4
https://github.com/dotnet/wcf
@@ -26,77 +26,77 @@
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
https://github.com/microsoft/vstest
@@ -222,9 +222,9 @@
https://github.com/dotnet/xharness
e9669dc84ecd668d3bbb748758103e23b394ffef
-
+
https://github.com/dotnet/arcade
- 92c39a4f0bacef20812f63e2e1d3f7aa8776038d
+ 7bca7a24dfc0eded1f3e364b4ff7bf1235b6eb26
https://dev.azure.com/dnceng/internal/_git/dotnet-optimization
diff --git a/eng/Versions.props b/eng/Versions.props
index 5affeb4f1c1316..55fd4981284a07 100644
--- a/eng/Versions.props
+++ b/eng/Versions.props
@@ -42,21 +42,21 @@
1.1.0-preview.22164.17
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 2.5.1-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
- 6.0.0-beta.23167.1
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 2.5.1-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
+ 6.0.0-beta.23211.7
6.0.0-preview.1.102
diff --git a/eng/pipelines/runtime-official.yml b/eng/pipelines/runtime-official.yml
index 445d91f0c79ef9..ae1b730798061b 100644
--- a/eng/pipelines/runtime-official.yml
+++ b/eng/pipelines/runtime-official.yml
@@ -140,7 +140,7 @@ stages:
# - windows_arm
# - windows_arm64
jobParameters:
- buildArgs: -s mono+libs+host+packs+mono.mscordbi -c $(_BuildConfig)
+ buildArgs: -s mono+libs+host+packs -c $(_BuildConfig)
nameSuffix: AllSubsets_Mono
isOfficialBuild: ${{ variables.isOfficialBuild }}
extraStepsTemplate: /eng/pipelines/common/upload-intermediate-artifacts-step.yml
diff --git a/eng/pipelines/runtime-staging.yml b/eng/pipelines/runtime-staging.yml
index 2a1591a398201b..b18c09d903343a 100644
--- a/eng/pipelines/runtime-staging.yml
+++ b/eng/pipelines/runtime-staging.yml
@@ -288,7 +288,7 @@ jobs:
jobParameters:
testScope: innerloop
nameSuffix: AllSubsets_Mono
- buildArgs: -s mono+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true
+ buildArgs: -s mono+mono.mscordbi+libs+host+packs+libs.tests -c $(_BuildConfig) /p:ArchiveTests=true
timeoutInMinutes: 120
condition: >-
or(
diff --git a/global.json b/global.json
index 46c71ec7dd04f3..85b8bcde770d49 100644
--- a/global.json
+++ b/global.json
@@ -1,21 +1,21 @@
{
"sdk": {
- "version": "6.0.115",
+ "version": "6.0.116",
"allowPrerelease": true,
"rollForward": "major"
},
"tools": {
- "dotnet": "6.0.115"
+ "dotnet": "6.0.116"
},
"native-tools": {
"cmake": "3.16.4",
"python3": "3.7.1"
},
"msbuild-sdks": {
- "Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.23167.1",
- "Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.23167.1",
- "Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.23167.1",
- "Microsoft.DotNet.SharedFramework.Sdk": "6.0.0-beta.23167.1",
+ "Microsoft.DotNet.Build.Tasks.TargetFramework.Sdk": "6.0.0-beta.23211.7",
+ "Microsoft.DotNet.Arcade.Sdk": "6.0.0-beta.23211.7",
+ "Microsoft.DotNet.Helix.Sdk": "6.0.0-beta.23211.7",
+ "Microsoft.DotNet.SharedFramework.Sdk": "6.0.0-beta.23211.7",
"Microsoft.Build.NoTargets": "3.1.0",
"Microsoft.Build.Traversal": "3.0.23",
"Microsoft.NET.Sdk.IL": "6.0.0-rc.1.21415.6"
diff --git a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs
index 7392b4de5daa6d..67f0e8205d0a33 100644
--- a/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs
+++ b/src/libraries/System.Net.Quic/src/System/Net/Quic/Implementations/MsQuic/Internal/MsQuicApi.cs
@@ -141,7 +141,9 @@ static MsQuicApi()
return;
}
- if (!NativeLibrary.TryLoad(Interop.Libraries.MsQuic, typeof(MsQuicApi).Assembly, DllImportSearchPath.AssemblyDirectory, out IntPtr msQuicHandle))
+ // Windows ships msquic in the assembly directory. Non-Windows relies an the package being installed on the system.
+ DllImportSearchPath? searchPath = OperatingSystem.IsWindows() ? DllImportSearchPath.AssemblyDirectory : null;
+ if (!NativeLibrary.TryLoad(Interop.Libraries.MsQuic, typeof(MsQuicApi).Assembly, searchPath, out IntPtr msQuicHandle))
{
// MsQuic library not loaded
return;
diff --git a/src/mono/mono/metadata/native-library.c b/src/mono/mono/metadata/native-library.c
index f01b9efbae5ddb..f84f2dc8e30611 100644
--- a/src/mono/mono/metadata/native-library.c
+++ b/src/mono/mono/metadata/native-library.c
@@ -92,7 +92,7 @@ mono_dllmap_lookup_list (MonoDllMap *dll_map, const char *dll, const char* func,
if (!dll_map)
goto exit;
- /*
+ /*
* we use the first entry we find that matches, since entries from
* the config file are prepended to the list and we document that the
* later entries win.
@@ -254,7 +254,7 @@ mono_global_dllmap_cleanup (void)
* This function is used to programatically add \c DllImport remapping in either
* a specific assembly, or as a global remapping. This is done by remapping
* references in a \c DllImport attribute from the \p dll library name into the \p tdll
- * name. If the \p dll name contains the prefix i:, the comparison of the
+ * name. If the \p dll name contains the prefix i:, the comparison of the
* library name is done without case sensitivity.
*
* If you pass \p func, this is the name of the \c EntryPoint in a \c DllImport if specified
@@ -518,21 +518,33 @@ netcore_probe_for_module (MonoImage *image, const char *file_name, int flags)
// TODO: this algorithm doesn't quite match CoreCLR, so respecting DLLIMPORTSEARCHPATH_LEGACY_BEHAVIOR makes little sense
// If the difference becomes a problem, overhaul this algorithm to match theirs exactly
- // Try without any path additions
+#if defined(HOST_ANDROID)
+ // On Android, try without any path additions first. It is sensitive to probing that will always miss
+ // and lookup for some libraries is required to use a relative path
module = netcore_probe_for_module_variations (NULL, file_name, lflags);
+#endif
// Check the NATIVE_DLL_SEARCH_DIRECTORIES
for (int i = 0; i < pinvoke_search_directories_count && module == NULL; ++i)
module = netcore_probe_for_module_variations (pinvoke_search_directories[i], file_name, lflags);
// Check the assembly directory if the search flag is set and the image exists
- if (flags & DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY && image != NULL && module == NULL) {
+ if ((flags & DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY) != 0 && image != NULL &&
+ module == NULL && (image->filename != NULL)) {
char *mdirname = g_path_get_dirname (image->filename);
if (mdirname)
module = netcore_probe_for_module_variations (mdirname, file_name, lflags);
g_free (mdirname);
}
+#if !defined(HOST_ANDROID)
+ // Try without any path additions
+ if (module == NULL)
+ {
+ module = netcore_probe_for_module_variations (NULL, file_name, lflags);
+ }
+#endif
+
// TODO: Pass remaining flags on to LoadLibraryEx on Windows where appropriate, see https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.dllimportsearchpath?view=netcore-3.1
return module;
@@ -1048,7 +1060,7 @@ lookup_pinvoke_call_impl (MonoMethod *method, MonoLookupPInvokeStatus *status_ou
mono_custom_attrs_free (cinfo);
}
if (flags < 0)
- flags = 0;
+ flags = DLLIMPORTSEARCHPATH_ASSEMBLY_DIRECTORY;
module = netcore_lookup_native_library (alc, image, new_scope, flags);
if (!module) {
@@ -1154,7 +1166,7 @@ pinvoke_probe_for_symbol (MonoDl *module, MonoMethodPInvoke *piinfo, const char
#if HOST_WIN32 && HOST_X86
/* Try the stdcall mangled name */
- /*
+ /*
* gcc under windows creates mangled names without the underscore, but MS.NET
* doesn't support it, so we doesn't support it either.
*/
@@ -1394,7 +1406,7 @@ mono_loader_save_bundled_library (int fd, uint64_t offset, uint64_t size, const
char *file, *buffer, *err, *internal_path;
if (!bundle_save_library_initialized)
bundle_save_library_initialize ();
-
+
file = g_build_filename (bundled_dylibrary_directory, destfname, (const char*)NULL);
buffer = g_str_from_file_region (fd, offset, size);
g_file_set_contents (file, buffer, size, NULL);
@@ -1409,7 +1421,7 @@ mono_loader_save_bundled_library (int fd, uint64_t offset, uint64_t size, const
mono_loader_register_module (internal_path, lib);
g_free (internal_path);
bundle_library_paths = g_slist_append (bundle_library_paths, file);
-
+
g_free (buffer);
}
diff --git a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
index bd1eb1be37de73..4e22339154be8c 100644
--- a/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
+++ b/src/tests/Common/CoreCLRTestLibrary/Utilities.cs
@@ -68,6 +68,9 @@ public static bool Verbose
public static bool IsWindows7 => IsWindows && Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1;
public static bool IsWindowsNanoServer => (!IsWindowsIoTCore && GetInstallationType().Equals("Nano Server", StringComparison.OrdinalIgnoreCase));
+ private static string _variant = Environment.GetEnvironmentVariable("DOTNET_RUNTIME_VARIANT");
+ public static bool IsMonoLLVMFULLAOT => _variant == "llvmfullaot";
+
// Windows 10 October 2018 Update
public static bool IsWindows10Version1809OrGreater =>
IsWindows && GetWindowsVersion() == 10 && GetWindowsMinorVersion() == 0 && GetWindowsBuildNumber() >= 17763;
diff --git a/src/tests/Common/testenvironment.proj b/src/tests/Common/testenvironment.proj
index c6d0a7c358d155..293feb331da49c 100644
--- a/src/tests/Common/testenvironment.proj
+++ b/src/tests/Common/testenvironment.proj
@@ -201,6 +201,8 @@
<_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'monointerpreter'" Include="set MONO_ENV_OPTIONS=--interpreter" />
+ <_TestEnvFileLine Condition="'$(RuntimeVariant)' != ''" Include="set DOTNET_RUNTIME_VARIANT=$(RuntimeVariant)" />
+
<_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set COMPlus_Interpret=%2A" />
<_TestEnvFileLine Condition="'$(Scenario)' == 'clrinterpreter'" Include="set COMPlus_InterpreterHWIntrinsicsIsSupportedFalse=1" />
@@ -216,6 +218,8 @@
<_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'monointerpreter'" Include="export MONO_ENV_OPTIONS=--interpreter" />
+ <_TestEnvFileLine Condition="'$(RuntimeVariant)' != ''" Include="export DOTNET_RUNTIME_VARIANT=$(RuntimeVariant)" />
+
<_TestEnvFileLine Condition="'$(RuntimeVariant)' == 'llvmaot'" Include="export MONO_ENV_OPTIONS=--llvm" />
diff --git a/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs b/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs
new file mode 100644
index 00000000000000..dcc6514ece1f15
--- /dev/null
+++ b/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.cs
@@ -0,0 +1,79 @@
+// Licensed to the .NET Foundation under one or more agreements.
+// The .NET Foundation licenses this file to you under the MIT license.
+
+using System;
+using System.IO;
+using System.Reflection;
+using System.Runtime.InteropServices;
+using Xunit;
+
+public class DllImportSearchPathsTest
+{
+ private static string Subdirectory => Path.Combine(NativeLibraryToLoad.GetDirectory(), "subdirectory");
+
+ static int Main(string[] args)
+ {
+ try
+ {
+ AssemblyDirectory_NotFound();
+ if (!TestLibrary.Utilities.IsMonoLLVMFULLAOT)
+ AssemblyDirectory_Found();
+
+ if (OperatingSystem.IsWindows())
+ AssemblyDirectory_Fallback_Found();
+ }
+ catch (Exception e)
+ {
+ Console.WriteLine($"Test Failure: {e}");
+ return 101;
+ }
+
+ return 100;
+ }
+
+ public static void AssemblyDirectory_NotFound()
+ {
+ // Library should not be found in the assembly directory
+ Assert.Throws(() => NativeLibraryPInvoke.Sum(1, 2));
+ }
+
+ public static void AssemblyDirectory_Found()
+ {
+ // Library should be found in the assembly directory
+ var assembly = Assembly.LoadFile(Path.Combine(Subdirectory, $"{nameof(DllImportSearchPathsTest)}.dll"));
+ var type = assembly.GetType(nameof(NativeLibraryPInvoke));
+ var method = type.GetMethod(nameof(NativeLibraryPInvoke.Sum));
+
+ int sum = (int)method.Invoke(null, new object[] { 1, 2 });
+ Assert.Equal(3, sum);
+ }
+
+ public static void AssemblyDirectory_Fallback_Found()
+ {
+ string currentDirectory = Environment.CurrentDirectory;
+ try
+ {
+ Environment.CurrentDirectory = Subdirectory;
+
+ // Library should not be found in the assembly directory, but should fall back to the default OS search which includes CWD on Windows
+ int sum = NativeLibraryPInvoke.Sum(1, 2);
+ Assert.Equal(3, sum);
+ }
+ finally
+ {
+ Environment.CurrentDirectory = currentDirectory;
+ }
+ }
+}
+
+public class NativeLibraryPInvoke
+{
+ public static int Sum(int a, int b)
+ {
+ return NativeSum(a, b);
+ }
+
+ [DllImport(NativeLibraryToLoad.Name)]
+ [DefaultDllImportSearchPaths(DllImportSearchPath.AssemblyDirectory)]
+ static extern int NativeSum(int arg1, int arg2);
+}
diff --git a/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.csproj b/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.csproj
new file mode 100644
index 00000000000000..70277c524034f7
--- /dev/null
+++ b/src/tests/Interop/DllImportSearchPaths/DllImportSearchPathsTest.csproj
@@ -0,0 +1,25 @@
+
+
+ Exe
+ true
+
+
+
+
+
+
+
+
+
+ $(OutDir)/subdirectory
+ -in-subdirectory
+
+
+ <_FilesToCopy Include="$(OutDir)/$(TargetName).dll" />
+ <_FilesToMove Include="$(OutDir)/libNativeLibrary.*" />
+ <_FilesToMove Include="$(OutDir)/NativeLibrary.*" />
+
+
+
+
+
diff --git a/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.cs b/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.cs
index 4742b2e0b5bdbb..699a125dfb2c42 100644
--- a/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.cs
+++ b/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.cs
@@ -110,13 +110,22 @@ public static int Main()
if (TestLibrary.Utilities.IsWindows &&
File.Exists(Path.Combine(Environment.SystemDirectory, libName)))
{
- // Calls on a valid library from System32 directory
+ // Library should be found in the system directory
success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.System32));
success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.System32));
- // Calls on a valid library from application directory
+ // Library should not be found in the assembly directory and should be found in the system directory
+ success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.System32));
+ success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory | DllImportSearchPath.System32));
+
+ // Library should not be found in the assembly directory, but should fall back to the default OS search which includes CWD on Windows
+ success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory));
+ success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory));
+
+ // Library should not be found in application directory
success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.ApplicationDirectory), TestResult.DllNotFound);
success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.ApplicationDirectory), TestResult.ReturnFailure);
+
}
// Calls with null libName input
@@ -134,6 +143,35 @@ public static int Main()
success &= EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory), TestResult.DllNotFound);
success &= EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory), TestResult.ReturnFailure);
+ string suffix = "-in-subdirectory";
+ libName = $"{NativeLibraryToLoad.Name}{suffix}";
+ string subdirectory = Path.Combine(testBinDir, "subdirectory");
+
+ if (!TestLibrary.Utilities.IsMonoLLVMFULLAOT)
+ {
+ // Library should be found in the assembly directory
+ Assembly assemblyInSubdirectory = Assembly.LoadFile(Path.Combine(subdirectory, $"{Path.GetFileNameWithoutExtension(assembly.Location)}{suffix}.dll"));
+ EXPECT(LoadLibraryAdvanced(libName, assemblyInSubdirectory, DllImportSearchPath.AssemblyDirectory));
+ EXPECT(TryLoadLibraryAdvanced(libName, assemblyInSubdirectory, DllImportSearchPath.AssemblyDirectory));
+ }
+
+ if (OperatingSystem.IsWindows())
+ {
+ string currentDirectory = Environment.CurrentDirectory;
+ try
+ {
+ Environment.CurrentDirectory = subdirectory;
+
+ // Library should not be found in the assembly directory, but should fall back to the default OS search which includes CWD on Windows
+ EXPECT(LoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory));
+ EXPECT(TryLoadLibraryAdvanced(libName, assembly, DllImportSearchPath.AssemblyDirectory));
+ }
+ finally
+ {
+ Environment.CurrentDirectory = currentDirectory;
+ }
+ }
+
// -----------------------------------------------
// FreeLibrary Tests
// -----------------------------------------------
diff --git a/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.csproj b/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.csproj
index 51c156e0d9b9e6..47cfe35cd59ecb 100644
--- a/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.csproj
+++ b/src/tests/Interop/NativeLibrary/API/NativeLibraryTests.csproj
@@ -16,4 +16,17 @@
+
+
+
+ $(OutDir)/subdirectory
+ -in-subdirectory
+
+
+
+
+
+
+
+
diff --git a/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs b/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs
index 4a61c599961f5a..efc878fd9fc520 100644
--- a/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs
+++ b/src/tests/Interop/NativeLibrary/NativeLibraryToLoad/NativeLibraryToLoad.cs
@@ -27,8 +27,11 @@ public static string GetFileName()
public static string GetFullPath()
{
- Assembly assembly = Assembly.GetExecutingAssembly();
- string directory = Path.GetDirectoryName(assembly.Location);
- return Path.Combine(directory, GetFileName());
+ return Path.Combine(GetDirectory(), GetFileName());
+ }
+
+ public static string GetDirectory()
+ {
+ return Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
}
}