Class cannot be cast to NSObject type of interface into the C# binding library Xamarin IOS

295 views Asked by At

I have created binding library through objective C framework, there is a class that are extending NsObject type of other interface(KsEvent), in Xamarin IOS, getting error during cast can't convert type of KSMEvent to KsEvent.

ApiDefinitions:

// @interface KSMEvent : NSObject <KsEvent> 
    [BaseType(typeof(NSObject))]
    interface KSMEvent : KsEvent
    {
        // @property NSDictionary * _Nullable userInfo;
        [NullAllowed, Export("userInfo", ArgumentSemantic.Assign)]
        NSDictionary UserInfo { get; set; }

        // -(instancetype _Nonnull)initWithName:(NSString * _Nonnull)name object:(id _Nullable)object userInfo:(NSDictionary * _Nullable)userInfo;
        [Export("initWithName:object:userInfo:")]
        IntPtr Constructor(string name, [NullAllowed] NSObject @object, [NullAllowed] NSDictionary userInfo);
    }

[BaseType(typeof(NSObject))]
    [Protocol, Model]
    interface KsEvent
    {
        // @required -(NSString * _Nonnull)getName;
        [Abstract]
        [Export("getName")]     
        string Name { get; }

        // @required -(id _Nullable)getObject;
        [Abstract]
        [NullAllowed, Export("getObject")]      
        NSObject Object { get; }

        // @required -(NSDictionary * _Nullable)getUserInfo;
        [Abstract]
        [NullAllowed, Export("getUserInfo")]        
        NSDictionary UserInfo { get; }
    }

Xamarin IOS:

KSMEvent kSMEvent = new KSMEvent();
KsEvent ksEvent = (KsEvent)kSMEvent;

** Error: Cannot convert type KSMEvent to KsEvent. **

0

There are 0 answers