Skip to content

System.UIntPtr is unsupported #546

Description

@stakx

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:

if ((type.IsPrimitive && type != typeof(IntPtr)))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions