Skip to content

Commit 3209414

Browse files
Copilotstephentoub
andcommitted
Use PlatformDetection class for .NET Framework detection
Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com>
1 parent 23d25d8 commit 3209414

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

tests/ModelContextProtocol.Tests/McpProtocolExceptionDataTests.cs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,6 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
6868
});
6969
}
7070

71-
// On .NET Framework, Exception.Data requires values to be serializable with [Serializable].
72-
// JsonElement is not marked as serializable, so these tests are skipped on .NET Framework.
73-
private static bool IsNetFramework =>
74-
#if NET
75-
false;
76-
#else
77-
true;
78-
#endif
79-
8071
[Fact]
8172
public async Task Exception_With_Serializable_Data_Propagates_To_Client()
8273
{
@@ -89,7 +80,7 @@ public async Task Exception_With_Serializable_Data_Propagates_To_Client()
8980
Assert.Equal((McpErrorCode)(-32002), exception.ErrorCode);
9081

9182
// Skip data verification on .NET Framework since JsonElement cannot be stored in Exception.Data
92-
if (IsNetFramework)
83+
if (PlatformDetection.IsNetFramework)
9384
{
9485
return;
9586
}
@@ -132,7 +123,7 @@ public async Task Exception_With_NonSerializable_Data_Still_Propagates_Error_To_
132123
Assert.Equal((McpErrorCode)(-32002), exception.ErrorCode);
133124

134125
// Skip data verification on .NET Framework since JsonElement cannot be stored in Exception.Data
135-
if (IsNetFramework)
126+
if (PlatformDetection.IsNetFramework)
136127
{
137128
return;
138129
}

tests/ModelContextProtocol.Tests/PlatformDetection.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ internal static class PlatformDetection
66
{
77
public static bool IsMonoRuntime { get; } = Type.GetType("Mono.Runtime") is not null;
88
public static bool IsWindows { get; } = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
9+
10+
// On .NET Framework, Exception.Data requires values to be serializable with [Serializable].
11+
// JsonElement is not marked as serializable, so certain features are not available on that platform.
12+
public static bool IsNetFramework { get; } =
13+
#if NET
14+
false;
15+
#else
16+
true;
17+
#endif
918
}

0 commit comments

Comments
 (0)