未验证 提交 e8a18d69 编写于 作者: M Marie Píchová 提交者: GitHub

Add more details in PlatformNotSupportedException (#89112)

上级 e2c04e07
......@@ -136,7 +136,7 @@
<value>Stream aborted by peer ({0}).</value>
</data>
<data name="SystemNetQuic_PlatformNotSupported" xml:space="preserve">
<value>System.Net.Quic is not supported on this platform.</value>
<value>System.Net.Quic is not supported on this platform: {0}</value>
</data>
<data name="net_quic_writing_notallowed" xml:space="preserve">
<value>Writing is not allowed on stream.</value>
......
......@@ -57,6 +57,7 @@ private MsQuicApi(QUIC_API_TABLE* apiTable)
internal static bool IsQuicSupported { get; }
internal static string MsQuicLibraryVersion { get; } = "unknown";
internal static string? NotSupportedReason { get; }
internal static bool UsesSChannelBackend { get; }
......@@ -69,11 +70,14 @@ static MsQuicApi()
bool loaded = false;
IntPtr msQuicHandle;
// MsQuic is using DualMode sockets and that will fail even for IPv4 if AF_INET6 is not available.
if (!Socket.OSSupportsIPv6)
{
NetEventSource.Info(null, "OS does not support dual mode sockets");
NotSupportedReason = "OS does not support dual mode sockets.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, NotSupportedReason);
}
return;
}
......@@ -92,9 +96,10 @@ static MsQuicApi()
if (!loaded)
{
// MsQuic library not loaded
NotSupportedReason = $"Unable to load MsQuic library version '{s_minMsQuicVersion.Major}'.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, $"Unable to load MsQuic library version '{s_minMsQuicVersion.Major}'.");
NetEventSource.Info(null, NotSupportedReason);
}
return;
}
......@@ -102,9 +107,14 @@ static MsQuicApi()
MsQuicOpenVersion = (delegate* unmanaged[Cdecl]<uint, QUIC_API_TABLE**, int>)NativeLibrary.GetExport(msQuicHandle, nameof(MsQuicOpenVersion));
MsQuicClose = (delegate* unmanaged[Cdecl]<QUIC_API_TABLE*, void>)NativeLibrary.GetExport(msQuicHandle, nameof(MsQuicClose));
if (!TryOpenMsQuic(out QUIC_API_TABLE* apiTable, out _))
if (!TryOpenMsQuic(out QUIC_API_TABLE* apiTable, out int openStatus))
{
// Too low version of the library (likely pre-2.0)
NotSupportedReason = $"MsQuicOpenVersion for version {s_minMsQuicVersion.Major} returned {openStatus} status code.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, NotSupportedReason);
}
return;
}
......@@ -144,9 +154,10 @@ static MsQuicApi()
if (version < s_minMsQuicVersion)
{
NotSupportedReason = $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, $"Incompatible MsQuic library version '{version}', expecting higher than '{s_minMsQuicVersion}'.");
NetEventSource.Info(null, NotSupportedReason);
}
return;
}
......@@ -167,9 +178,10 @@ static MsQuicApi()
// Implies windows platform, check TLS1.3 availability
if (!IsWindowsVersionSupported())
{
NotSupportedReason = $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}.";
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, $"Current Windows version ({Environment.OSVersion}) is not supported by QUIC. Minimal supported version is {s_minWindowsVersion}");
NetEventSource.Info(null, NotSupportedReason);
}
return;
}
......@@ -208,11 +220,6 @@ private static bool TryOpenMsQuic(out QUIC_API_TABLE* apiTable, out int openStat
openStatus = MsQuicOpenVersion((uint)s_minMsQuicVersion.Major, &table);
if (StatusFailed(openStatus))
{
if (NetEventSource.Log.IsEnabled())
{
NetEventSource.Info(null, $"MsQuicOpenVersion for version {s_minMsQuicVersion.Major} returned {openStatus} status code.");
}
apiTable = null;
return false;
}
......
......@@ -64,7 +64,7 @@ public static ValueTask<QuicConnection> ConnectAsync(QuicClientConnectionOptions
{
if (!IsSupported)
{
throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported);
throw new PlatformNotSupportedException(SR.Format(SR.SystemNetQuic_PlatformNotSupported, MsQuicApi.NotSupportedReason));
}
// Validate and fill in defaults for the options.
......
......@@ -48,7 +48,7 @@ public static ValueTask<QuicListener> ListenAsync(QuicListenerOptions options, C
{
if (!IsSupported)
{
throw new PlatformNotSupportedException(SR.SystemNetQuic_PlatformNotSupported);
throw new PlatformNotSupportedException(SR.Format(SR.SystemNetQuic_PlatformNotSupported, MsQuicApi.NotSupportedReason));
}
// Validate and fill in defaults for the options.
......
......@@ -15,10 +15,12 @@ public class MsQuicPlatformDetectionTests : QuicTestBase
public static bool IsQuicUnsupported => !IsSupported;
[ConditionalFact(nameof(IsQuicUnsupported))]
public void UnsupportedPlatforms_ThrowsPlatformNotSupportedException()
public async Task UnsupportedPlatforms_ThrowsPlatformNotSupportedException()
{
Assert.ThrowsAsync<PlatformNotSupportedException>(async () => await CreateQuicListener());
Assert.ThrowsAsync<PlatformNotSupportedException>(async () => await CreateQuicConnection(new IPEndPoint(IPAddress.Loopback, 0)));
PlatformNotSupportedException listenerEx = await Assert.ThrowsAsync<PlatformNotSupportedException>(async () => await CreateQuicListener());
PlatformNotSupportedException connectionEx = await Assert.ThrowsAsync<PlatformNotSupportedException>(async () => await CreateQuicConnection(new IPEndPoint(IPAddress.Loopback, 0)));
Assert.Equal(listenerEx.Message, connectionEx.Message);
_output.WriteLine(listenerEx.Message);
}
[ActiveIssue("https://github.com/dotnet/runtime/issues/73290", typeof(PlatformDetection), nameof(PlatformDetection.IsSingleFile))]
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册