Forum Xamarin.iOS

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

Prashant03Prashant03 Member ✭✭
edited September 2020 in Xamarin.iOS

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.


 // @interface KSMEvent : NSObject <KsEvent> 
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;
    IntPtr Constructor(string name, [NullAllowed] NSObject @object, [NullAllowed] NSDictionary userInfo);

[Protocol, Model]
interface KsEvent
    // @required -(NSString * _Nonnull)getName;
    string Name { get; }

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

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

Xamarin IOS:

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

Error: Cannot convert type KSMEvent to KsEvent.



Sign In or Register to comment.