Forum Xamarin.iOS
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

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

Prashant03Prashant03 Member ✭✭
edited September 30 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.

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.

Tagged:

Answers

Sign In or Register to comment.