Skip to content

Commit 2eb7dd0

Browse files
authored
Merge pull request #109742 from vseanreesermsft/internal-merge-8.0-2024-11-12-1233
Merging internal commits for release/8.0
2 parents 18be5f1 + 0cb305f commit 2eb7dd0

File tree

1 file changed

+19
-4
lines changed
  • src/libraries/System.Net.Quic/src/System/Net/Quic/Internal

1 file changed

+19
-4
lines changed

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

+19-4
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
{
@@ -154,7 +169,7 @@ static MsQuicApi()
154169

155170
if (version < s_minMsQuicVersion)
156171
{
157-
NotSupportedReason = $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.";
172+
NotSupportedReason = $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.";
158173
if (NetEventSource.Log.IsEnabled())
159174
{
160175
NetEventSource.Info(null, NotSupportedReason);
@@ -178,7 +193,7 @@ static MsQuicApi()
178193
// Implies windows platform, check TLS1.3 availability
179194
if (!IsWindowsVersionSupported())
180195
{
181-
NotSupportedReason = $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}.";
196+
NotSupportedReason = $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}.";
182197
if (NetEventSource.Log.IsEnabled())
183198
{
184199
NetEventSource.Info(null, NotSupportedReason);

0 commit comments

Comments
 (0)