Skip to content

Commit 3a6fc48

Browse files
committed
Use explicit full-path for loading MsQuic.dll
1 parent b236305 commit 3a6fc48

File tree

1 file changed

+17
-2
lines changed
  • src/libraries/System.Net.Quic/src/System/Net/Quic/Internal

1 file changed

+17
-2
lines changed

src/libraries/System.Net.Quic/src/System/Net/Quic/Internal/MsQuicApi.cs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,23 @@ static MsQuicApi()
8383

8484
if (OperatingSystem.IsWindows())
8585
{
86-
// Windows ships msquic in the assembly directory.
87-
loaded = NativeLibrary.TryLoad(Interop.Libraries.MsQuic, typeof(MsQuicApi).Assembly, DllImportSearchPath.AssemblyDirectory, out msQuicHandle);
86+
#pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
87+
// Windows ships msquic in the assembly directory next to System.Net.Quic, so load that
88+
// for single-file deployments, the assembly location is an empty string so we fall back
89+
// to AppContext.BaseDirectory which is the directory containing the single-file executable
90+
string path = typeof(MsQuicApi).Assembly.Location is string assemblyLocation && !string.IsNullOrEmpty(assemblyLocation)
91+
? System.IO.Path.GetDirectoryName(assemblyLocation)!
92+
: AppContext.BaseDirectory;
93+
#pragma warning restore IL3000
94+
95+
path = System.IO.Path.Combine(path, Interop.Libraries.MsQuic);
96+
97+
if (NetEventSource.Log.IsEnabled())
98+
{
99+
NetEventSource.Info(null, $"Attempting to load MsQuic from {path}");
100+
}
101+
102+
loaded = NativeLibrary.TryLoad(path, typeof(MsQuicApi).Assembly, DllImportSearchPath.LegacyBehavior, out msQuicHandle);
88103
}
89104
else
90105
{

0 commit comments

Comments
 (0)