# Haxe CS resolving native methoeds to base class instead of overriden method

**URL:** https://community.haxe.org/t/haxe-cs-resolving-native-methoeds-to-base-class-instead-of-overriden-method/4073
**Category:** Haxe
**Tags:** haxe-cs
**Created:** [November 2, 2023, 4:48pm UTC](https://community.haxe.org/t/haxe-cs-resolving-native-methoeds-to-base-class-instead-of-overriden-method/4073 "2023-11-02T16:48:52Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![neimanpinchas](https://community.haxe.org/user_avatar/community.haxe.org/neimanpinchas/32/2348_2.png) [@neimanpinchas](https://community.haxe.org/u/neimanpinchas)
#### Post date: [November 2, 2023, 4:48pm UTC](https://community.haxe.org/t/haxe-cs-resolving-native-methoeds-to-base-class-instead-of-overriden-method/4073/1 "2023-11-02T16:48:52Z")

</div>

I am trying to share an observable colletion between haxe code and UI code.  
Given that the observible collection could only be modified by the UI thread, I am using an overriden version of the library that is overriding the add method to dispatch the UI thread.

For some odd reason, the haxe compiler is casting the instance to the base class before calling the Add method, causing the original Method to be calle instead of the original,

Any workaround?

Haxe

```haxe
public var conv_status=new mintplayer.observablecollection.ObservableCollection_1<KV>();
conv_status.Add({k:"Init",v:Date.now().toString()});

```

Library

```haxe
public new void Add(T item)
        {
            CheckReentrancy();
            RunOnMainThread((param) =>
            {
                base.Add(param);
                OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, param));
            }, item );
        }

```

Haxe generated code

```haxe
( this.conv_status as global::System.Collections.ObjectModel.Collection<global::conveyor.KV> ).Add(((global::conveyor.KV) (new global::conveyor.KV(((string) (key) ), ((string) (val) ))) ));
	

```

---

<div class="post-metadata">

### Author: ![acarioni](https://avatars.discourse-cdn.com/v2/letter/a/65b543/32.png) [@acarioni](https://community.haxe.org/u/acarioni)
#### Post date: [November 3, 2023, 7:22am UTC](https://community.haxe.org/t/haxe-cs-resolving-native-methoeds-to-base-class-instead-of-overriden-method/4073/2 "2023-11-03T07:22:43Z")

</div>

If the C# library is yours, you can declare the Add method as virtual.
