0

I have an issue with duplicated constructor in Xamarin iOS binding library with code generated by sharpie tool from third-party SDK code. Basicly C# generated interface is using NSFileHandle as a base type and SDK header file declares identical designated initializer in its subclass like in NSFileHandler so I'm getting "Member ... is already defined error" because now binding library is generating C# constructor twice - first time from the base class and the second from subclassed initializer.

Objective-C code:

@interface MyFileHandle : NSFileHandle
//...
- (nullable instancetype)initWithCoder:(NSCoder *)coder NS_DESIGNATED_INITIALIZER;
//...

C# binding library code:

[BaseType(typeof(NSFileHandle))]
public interface MyFileHandle
{
    //...
    [Export("initWithCoder:")]
    [DesignatedInitializer]
    IntPtr Constructor(NSCoder coder);
    //...
}

Binding library generated code (*.g.cs):

[Register("MyFileHandle", true)]
public unsafe partial class MyFileHandle : NSFileHandle {
    //...
    [CompilerGenerated]
    [DesignatedInitializer]
    [EditorBrowsable (EditorBrowsableState.Advanced)]
    [Export ("initWithCoder:")]
    public MyFileHandle (NSCoder coder) : base (NSObjectFlag.Empty)
    {
        //...
    }

    [Export ("initWithCoder:")]
    [DesignatedInitializer]
    [CompilerGenerated]
    public MyFileHandle (NSCoder coder)
        : base (NSObjectFlag.Empty)
    {
       //...
    }
    //...
}

How can I prevent binding library from generating constructors twice thus get rid of the error?

awattar
  • 446
  • 5
  • 19
  • 2
    Just remove the one from the `ApiDefinitions.cs` so you only get one `CompilerGenerated` version in your auto-generated `.g.cs`. – SushiHangover Mar 07 '17 at 02:25
  • It seems to be a mismatch between sharpie and binding library code generator. So generator should look through the code first and omit constructor creation for base class when there is one in subclass already or sharpie should not generate constructors for designated initializers. – awattar Mar 07 '17 at 07:56

1 Answers1

0

It seems that you can simply remove duplicated Constructor from ApiDefinitions.cs as @SushiHangover suggested.

awattar
  • 446
  • 5
  • 19