0

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. **

  • Hi, have a try with `KsEvent ksEvent = new KsEvent(); kSMEvent ksMEvent = (kSMEvent )ksEvent ;` to check whether this will work. – Junior Jiang Sep 29 '20 at 09:12
  • Hello @JuniorJiang-MSFT , In that scenario you are casting KsEvent to KSMEvent, but i need to cast KSMEvent to KsEvent and ya i tried this as well it is showing error cannot cast KsEvent to KSMEvent. – Prashant Gautam Sep 29 '20 at 09:23
  • You're right. Now this way also can not work. I will continue to research it, if good news will update here. – Junior Jiang Sep 29 '20 at 09:32
  • Hi, you also can submit this problem in Github [here](https://github.com/xamarin/xamarin-macios/issues). Then there will be engineers from Microsoft to help you check this problem. – Junior Jiang Sep 30 '20 at 09:00

0 Answers0