Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.UIntPtr is unsupported #546

Closed
stakx opened this issue Jan 2, 2021 · 0 comments · Fixed by #547
Closed

System.UIntPtr is unsupported #546

stakx opened this issue Jan 2, 2021 · 0 comments · Fixed by #547
Assignees
Labels
Milestone

Comments

@stakx
Copy link
Member

stakx commented Jan 2, 2021

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)))

@stakx stakx added the bug label Jan 2, 2021
@stakx stakx changed the title Support for native integer types (nint and nuint in C# 9) System.UIntPtr is unsupported Jan 2, 2021
@stakx stakx self-assigned this Jan 3, 2021
@stakx stakx added this to the v5.0.0 milestone Jan 3, 2021
@stakx stakx closed this as completed in #547 Jan 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant