@@ -85,8 +85,23 @@ static MsQuicApi()
85
85
86
86
if ( OperatingSystem . IsWindows ( ) )
87
87
{
88
- // Windows ships msquic in the assembly directory.
89
- loaded = NativeLibrary . TryLoad ( Interop . Libraries . MsQuic , typeof ( MsQuicApi ) . Assembly , DllImportSearchPath . AssemblyDirectory , out msQuicHandle ) ;
88
+ #pragma warning disable IL3000 // Avoid accessing Assembly file path when publishing as a single file
89
+ // Windows ships msquic in the assembly directory next to System.Net.Quic, so load that.
90
+ // For single-file deployments, the assembly location is an empty string so we fall back
91
+ // to AppContext.BaseDirectory which is the directory containing the single-file executable.
92
+ string path = typeof ( MsQuicApi ) . Assembly . Location is string assemblyLocation && ! string . IsNullOrEmpty ( assemblyLocation )
93
+ ? System . IO . Path . GetDirectoryName ( assemblyLocation ) !
94
+ : AppContext . BaseDirectory ;
95
+ #pragma warning restore IL3000
96
+
97
+ path = System . IO . Path . Combine ( path , Interop . Libraries . MsQuic ) ;
98
+
99
+ if ( NetEventSource . Log . IsEnabled ( ) )
100
+ {
101
+ NetEventSource . Info ( null , $ "Attempting to load MsQuic from { path } ") ;
102
+ }
103
+
104
+ loaded = NativeLibrary . TryLoad ( path , typeof ( MsQuicApi ) . Assembly , DllImportSearchPath . LegacyBehavior , out msQuicHandle ) ;
90
105
}
91
106
else
92
107
{
@@ -156,7 +171,7 @@ static MsQuicApi()
156
171
157
172
if ( version < s_minMsQuicVersion )
158
173
{
159
- NotSupportedReason = $ "Incompatible MsQuic library version '{ version } ', expecting higher than '{ s_minMsQuicVersion } '.";
174
+ NotSupportedReason = $ "Incompatible MsQuic library version '{ version } ', expecting higher than '{ s_minMsQuicVersion } '.";
160
175
if ( NetEventSource . Log . IsEnabled ( ) )
161
176
{
162
177
NetEventSource . Info ( null , NotSupportedReason ) ;
@@ -180,7 +195,7 @@ static MsQuicApi()
180
195
// Implies windows platform, check TLS1.3 availability
181
196
if ( ! IsWindowsVersionSupported ( ) )
182
197
{
183
- NotSupportedReason = $ "Current Windows version ({ Environment . OSVersion } ) is not supported by QUIC. Minimal supported version is { s_minWindowsVersion } .";
198
+ NotSupportedReason = $ "Current Windows version ({ Environment . OSVersion } ) is not supported by QUIC. Minimal supported version is { s_minWindowsVersion } .";
184
199
if ( NetEventSource . Log . IsEnabled ( ) )
185
200
{
186
201
NetEventSource . Info ( null , NotSupportedReason ) ;
0 commit comments