@@ -26,6 +26,7 @@ namespace StreamJsonRpc;
2626/// <remarks>
2727/// Each instance of this class may only be used with a single <see cref="JsonRpc" /> instance.
2828/// </remarks>
29+ [ RequiresDynamicCode ( RuntimeReasons . Formatters ) , RequiresUnreferencedCode ( RuntimeReasons . Formatters ) ]
2930public class JsonMessageFormatter : FormatterBase , IJsonRpcAsyncMessageTextFormatter , IJsonRpcMessageFactory
3031{
3132 /// <summary>
@@ -1009,6 +1010,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
10091010 /// <summary>
10101011 /// Converts a progress token to an <see cref="IProgress{T}"/>.
10111012 /// </summary>
1013+ [ RequiresDynamicCode ( RuntimeReasons . CloseGenerics ) ]
10121014 private class JsonProgressServerConverter : JsonConverter
10131015 {
10141016 private readonly JsonMessageFormatter formatter ;
@@ -1042,6 +1044,7 @@ public override void WriteJson(JsonWriter writer, object? value, JsonSerializer
10421044 /// <summary>
10431045 /// Converts an enumeration token to an <see cref="IAsyncEnumerable{T}"/>.
10441046 /// </summary>
1047+ [ RequiresDynamicCode ( RuntimeReasons . CloseGenerics ) ]
10451048 private class AsyncEnumerableConsumerConverter : JsonConverter
10461049 {
10471050 private static readonly MethodInfo ReadJsonOpenGenericMethod = typeof ( AsyncEnumerableConsumerConverter ) . GetMethods ( BindingFlags . Instance | BindingFlags . NonPublic ) . Single ( m => m . Name == nameof ( ReadJson ) && m . IsGenericMethod ) ;
@@ -1062,7 +1065,7 @@ internal AsyncEnumerableConsumerConverter(JsonMessageFormatter jsonMessageFormat
10621065 return null ;
10631066 }
10641067
1065- Type ? iface = TrackerHelpers < IAsyncEnumerable < int > > . FindInterfaceImplementedBy ( objectType ) ;
1068+ Type ? iface = TrackerHelpers . FindIAsyncEnumerableInterfaceImplementedBy ( objectType ) ;
10661069 Assumes . NotNull ( iface ) ;
10671070 MethodInfo genericMethod = ReadJsonOpenGenericMethod . MakeGenericMethod ( iface . GenericTypeArguments [ 0 ] ) ;
10681071 try
@@ -1100,6 +1103,7 @@ private IAsyncEnumerable<T> ReadJson<T>(JsonReader reader, JsonSerializer serial
11001103 /// <summary>
11011104 /// Converts an instance of <see cref="IAsyncEnumerable{T}"/> to an enumeration token.
11021105 /// </summary>
1106+ [ RequiresDynamicCode ( RuntimeReasons . CloseGenerics ) ]
11031107 private class AsyncEnumerableGeneratorConverter : JsonConverter
11041108 {
11051109 private static readonly MethodInfo WriteJsonOpenGenericMethod = typeof ( AsyncEnumerableGeneratorConverter ) . GetMethods ( BindingFlags . NonPublic | BindingFlags . Instance ) . Single ( m => m . Name == nameof ( WriteJson ) && m . IsGenericMethod ) ;
@@ -1120,7 +1124,7 @@ internal AsyncEnumerableGeneratorConverter(JsonMessageFormatter jsonMessageForma
11201124
11211125 public override void WriteJson ( JsonWriter writer , object ? value , JsonSerializer serializer )
11221126 {
1123- Type ? iface = TrackerHelpers < IAsyncEnumerable < int > > . FindInterfaceImplementedBy ( value ! . GetType ( ) ) ;
1127+ Type ? iface = TrackerHelpers . FindIAsyncEnumerableInterfaceImplementedBy ( value ! . GetType ( ) ) ;
11241128 Assumes . NotNull ( iface ) ;
11251129 MethodInfo genericMethod = WriteJsonOpenGenericMethod . MakeGenericMethod ( iface . GenericTypeArguments [ 0 ] ) ;
11261130 try
@@ -1249,7 +1253,9 @@ public override void WriteJson(JsonWriter writer, Stream? value, JsonSerializer
12491253 }
12501254
12511255 [ DebuggerDisplay ( "{" + nameof ( DebuggerDisplay ) + "}" ) ]
1252- private class RpcMarshalableConverter ( Type interfaceType , JsonMessageFormatter jsonMessageFormatter , JsonRpcProxyOptions proxyOptions , JsonRpcTargetOptions targetOptions , RpcMarshalableAttribute rpcMarshalableAttribute ) : JsonConverter
1256+ [ RequiresDynamicCode ( RuntimeReasons . CloseGenerics ) ]
1257+ [ RequiresUnreferencedCode ( RuntimeReasons . RefEmit ) ]
1258+ private class RpcMarshalableConverter ( [ DynamicallyAccessedMembers ( DynamicallyAccessedMemberTypes . PublicEvents | DynamicallyAccessedMemberTypes . NonPublicEvents | DynamicallyAccessedMemberTypes . Interfaces ) ] Type interfaceType , JsonMessageFormatter jsonMessageFormatter , JsonRpcProxyOptions proxyOptions , JsonRpcTargetOptions targetOptions , RpcMarshalableAttribute rpcMarshalableAttribute ) : JsonConverter
12531259 {
12541260 private string DebuggerDisplay => $ "Converter for marshalable objects of type { interfaceType . FullName } ";
12551261
@@ -1333,6 +1339,7 @@ public object Convert(object value, TypeCode typeCode)
13331339 public ulong ToUInt64 ( object value ) => ( ( JToken ) value ) . ToObject < ulong > ( this . serializer ) ;
13341340 }
13351341
1342+ [ RequiresUnreferencedCode ( RuntimeReasons . LoadType ) ]
13361343 private class ExceptionConverter : JsonConverter < Exception ? >
13371344 {
13381345 /// <summary>
0 commit comments