@@ -83,8 +83,23 @@ static MsQuicApi()
83
83
84
84
if ( OperatingSystem . IsWindows ( ) )
85
85
{
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 ) ;
88
103
}
89
104
else
90
105
{
@@ -154,7 +169,7 @@ static MsQuicApi()
154
169
155
170
if ( version < s_minMsQuicVersion )
156
171
{
157
- NotSupportedReason = $ "Incompatible MsQuic library version '{ version } ', expecting higher than '{ s_minMsQuicVersion } '.";
172
+ NotSupportedReason = $ "Incompatible MsQuic library version '{ version } ', expecting higher than '{ s_minMsQuicVersion } '.";
158
173
if ( NetEventSource . Log . IsEnabled ( ) )
159
174
{
160
175
NetEventSource . Info ( null , NotSupportedReason ) ;
@@ -178,7 +193,7 @@ static MsQuicApi()
178
193
// Implies windows platform, check TLS1.3 availability
179
194
if ( ! IsWindowsVersionSupported ( ) )
180
195
{
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 } .";
182
197
if ( NetEventSource . Log . IsEnabled ( ) )
183
198
{
184
199
NetEventSource . Info ( null , NotSupportedReason ) ;
0 commit comments