diff --git a/src/StreamJsonRpc/JsonRpc.cs b/src/StreamJsonRpc/JsonRpc.cs index 230c3c0a0..add25ef0b 100644 --- a/src/StreamJsonRpc/JsonRpc.cs +++ b/src/StreamJsonRpc/JsonRpc.cs @@ -7,6 +7,7 @@ using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Reflection; +using System.Runtime.CompilerServices; using Microsoft.VisualStudio.Threading; using Newtonsoft.Json; using StreamJsonRpc.Protocol; @@ -2775,6 +2776,13 @@ private T CreateProxy(ReadOnlySpan additionalContractInterfaces, ReadOn [RequiresDynamicCode(RuntimeReasons.RefEmit), RequiresUnreferencedCode(RuntimeReasons.RefEmit)] private IJsonRpcClientProxyInternal CreateProxy(Type contractInterface, ReadOnlySpan additionalContractInterfaces, ReadOnlySpan<(Type Type, int Code)> implementedOptionalInterfaces, JsonRpcProxyOptions? options, long? marshaledObjectHandle) { +#if !NETSTANDARD2_0 + if (!RuntimeFeature.IsDynamicCodeSupported) + { + throw new NotSupportedException("CreateProxy is not supported if dynamic code is not supported."); + } +#endif + TypeInfo proxyType = ProxyGeneration.Get(contractInterface, additionalContractInterfaces, implementedOptionalInterfaces); return (IJsonRpcClientProxyInternal)Activator.CreateInstance( proxyType.AsType(),