Foundation.ModelNotImplementedException thrown when calling MethodToProperty method

LukePothierLukePothier USMember ✭✭

I used Objective Sharpie to generate an ApiDefinition.cs which contains the following:

// @optional -(NSString *)myString;
// @optional -(void)setMyString:(NSString *)myString;
[Export("myString")]
[Verify(MethodToProperty)]
string MyString { get; set; }

From the Objective-C source header which looks like:

@optional
-(void)setMyString:(NSString *)myString;
-(NSString *)myString;

I'm able to call the SetMyString(string) and GetMyString() methods fine, but trying to set the mapped MyString property throws a Foundation.ModelNotImplementedException. When I decompile the .dll, I can see that the get/set methods on MyString just directly throw the exception:

[BindingImpl]
public virtual string MyString
{
    [Export("myString")]
    get
    {
        throw new ModelNotImplementedException();
    }
    [Export("setMyString:")]
    set
    {
        throw new ModelNotImplementedException();
    }
}

However, the _Extensions class that was generated for the type that contains the method has the extension methods implemented as expected:

[BindingImpl]
public static string GetMyString(this IMyType This)
{
    return NSString.FromHandle(Messaging.IntPtr_objc_msgSend(This.get_Handle(), Selector.GetHandle("myString")));
}

[BindingImpl]
public static void SetMyString(this IMyType This, string value)
{
    if (value == null)
    {
        throw new ArgumentNullException("value");
    }
    IntPtr nsvalue = NSString.CreateNative(value);
    Messaging.void_objc_msgSend_IntPtr(This.get_Handle(), Selector.GetHandle("setMyString:"), nsvalue);
    NSString.ReleaseNative(nsvalue);
}

Does anyone have any idea why this might be? Is the correct approach to remove the property from the API and force the use of the extension methods? Is there a way to have the get/set methods implement the same code that the extension methods do?

Answers

  • NateDudleyNateDudley USMember

    Are these forums still active? I'm having the same issue and every question on here that relates to the same issue has zero responses.

  • LukePothierLukePothier USMember ✭✭

    @NateDudley they are, but it seems like there aren't that many people actively binding libraries. I ended up giving up and using the generated extension methods, and then wrapping the whole .dll in my own API so I could proxy those calls through getters and setters.

Sign In or Register to comment.