@@ -10,6 +10,11 @@ namespace ModelContextProtocol.Tests;
1010/// <summary>
1111/// Tests for McpProtocolException.Data propagation to JSON-RPC error responses.
1212/// </summary>
13+ /// <remarks>
14+ /// Note: On .NET Framework, Exception.Data requires values to be serializable with [Serializable].
15+ /// Since JsonElement is not marked as serializable, the data population on the client side is skipped
16+ /// on that platform. These tests verify the error message and code are correct regardless of platform.
17+ /// </remarks>
1318public class McpProtocolExceptionDataTests : ClientServerTestBase
1419{
1520 public McpProtocolExceptionDataTests ( ITestOutputHelper testOutputHelper )
@@ -63,6 +68,15 @@ protected override void ConfigureServices(ServiceCollection services, IMcpServer
6368 } ) ;
6469 }
6570
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+
6680 [ Fact ]
6781 public async Task Exception_With_Serializable_Data_Propagates_To_Client ( )
6882 {
@@ -73,6 +87,12 @@ public async Task Exception_With_Serializable_Data_Propagates_To_Client()
7387
7488 Assert . Equal ( "Request failed (remote): Resource not found" , exception . Message ) ;
7589 Assert . Equal ( ( McpErrorCode ) ( - 32002 ) , exception . ErrorCode ) ;
90+
91+ // Skip data verification on .NET Framework since JsonElement cannot be stored in Exception.Data
92+ if ( IsNetFramework )
93+ {
94+ return ;
95+ }
7696
7797 // Verify the data was propagated to the exception
7898 // The Data collection should contain the expected keys
@@ -110,6 +130,12 @@ public async Task Exception_With_NonSerializable_Data_Still_Propagates_Error_To_
110130
111131 Assert . Equal ( "Request failed (remote): Resource not found" , exception . Message ) ;
112132 Assert . Equal ( ( McpErrorCode ) ( - 32002 ) , exception . ErrorCode ) ;
133+
134+ // Skip data verification on .NET Framework since JsonElement cannot be stored in Exception.Data
135+ if ( IsNetFramework )
136+ {
137+ return ;
138+ }
113139
114140 // Verify that only the serializable data was propagated (non-serializable was filtered out)
115141 var hasUri = false ;
0 commit comments