This project is read-only.

Bug in interface member generation


I have found that if you have this scenario of inheritance:
public class myclass : IBaseClass
{ }
public interface IBaseClass : IInheritedClass
public interface IInheritedClass
then bmethod() will get generated twice and you will receive this message when trying to establish the proxy: "Method 'bmethod' on type .... is overriding a method that has been overridden." and will fail to connect.
You need to change the method GenerateMethodImpl within AbstractClassBuilder to the code below to cope with the issue:


    protected virtual void GenerateMethodImpl ( TypeBuilder builder, Type currentType, List<Type> alreadyImplemented = null)
        if ( alreadyImplemented == null )
            alreadyImplemented = new List<Type>();
        MethodInfo[] methods = currentType.GetMethods();
        foreach (MethodInfo method in methods)
            Type[] parameterTypes = GetParameters(method.GetParameters()); // declare the method with the correct parameters
            MethodBuilder methodBuilder = builder.DefineMethod(method.Name, defaultMethodAttributes, method.ReturnType, parameterTypes);
            // Start building the method
            methodBuilder.CreateMethodBody(null, 0);
            ILGenerator iLGenerator = methodBuilder.GetILGenerator();
            GenerateMethodImpl(method, parameterTypes, iLGenerator);
            // declare that we override the interface method
            builder.DefineMethodOverride(methodBuilder, method);
        Type[] inheritedInterfaces = currentType.GetInterfaces();
        foreach (Type inheritedInterface in inheritedInterfaces)
                GenerateMethodImpl( builder, inheritedInterface, alreadyImplemented );