-
Notifications
You must be signed in to change notification settings - Fork 485
Closed
Description
DynamicProxy apparently doesn't support System.UIntPtr properly. This may become more of an issue now that C# 9 has a dedicated keyword for this type (nuint).
This short program:
class ProxyNothingHook : IProxyGenerationHook
{
public bool ShouldInterceptMethod(Type type, MethodInfo methodInfo) => false;
public void MethodsInspected() { }
public void NonProxyableMemberNotification(Type type, MemberInfo memberInfo) { }
}
public interface INativeInts
{
nint GetNint();
nuint GetNuint();
}
var generator = new ProxyGenerator();
var options = new ProxyGenerationOptions(new ProxyNothingHook());
var proxy = generator.CreateInterfaceProxyWithoutTarget<INativeInts>(options);will fail with:
System.NotSupportedException: Specified method is not supported.
at Castle.DynamicProxy.Generators.Emitters.OpCodeUtil.EmitLoadOpCodeForDefaultValueOfType(ILGenerator gen, Type type)
at Castle.DynamicProxy.Generators.Emitters.SimpleAST.DefaultValueExpression.Emit(IMemberEmitter member, ILGenerator gen)
at Castle.DynamicProxy.Generators.Emitters.SimpleAST.ReturnStatement.Emit(IMemberEmitter member, ILGenerator gen)
at Castle.DynamicProxy.Generators.Emitters.CodeBuilders.AbstractCodeBuilder.Generate(IMemberEmitter member, ILGenerator il)
at Castle.DynamicProxy.Generators.Emitters.MethodEmitter.Generate()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.EnsureBuildersAreInAValidState()
at Castle.DynamicProxy.Generators.Emitters.AbstractTypeEmitter.BuildType()
at Castle.DynamicProxy.Generators.InterfaceProxyWithoutTargetGenerator.GenerateType(String typeName, Type proxyTargetType, Type[] interfaces, INamingScope namingScope)
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.<>c__DisplayClass6_0.<GenerateCode>b__0(String n, INamingScope s)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.<>c__DisplayClass34_0.<ObtainProxyType>b__0(CacheKey _)
at Castle.Core.Internal.SynchronizedDictionary`2.GetOrAdd(TKey key, Func`2 valueFactory)
at Castle.DynamicProxy.Generators.BaseProxyGenerator.ObtainProxyType(CacheKey cacheKey, Func`3 factory)
at Castle.DynamicProxy.Generators.InterfaceProxyWithTargetGenerator.GenerateCode(Type proxyTargetType, Type[] interfaces, ProxyGenerationOptions options)
at Castle.DynamicProxy.DefaultProxyBuilder.CreateInterfaceProxyTypeWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget(Type interfaceToProxy, Type[] additionalInterfacesToProxy, ProxyGenerationOptions options, IInterceptor[] interceptors)
at Castle.DynamicProxy.ProxyGenerator.CreateInterfaceProxyWithoutTarget[TInterface](ProxyGenerationOptions options, IInterceptor[] interceptors)
at ...
I narrowed this down to just UIntPtr, which isn't covered here:
Core/src/Castle.Core/DynamicProxy/Generators/Emitters/SimpleAST/DefaultValueExpression.cs
Line 75 in 5f28652
| if ((type.IsPrimitive && type != typeof(IntPtr))) |
Reactions are currently unavailable