Hello all,

I have an interop class that wraps a native class. Everything works great except in one function in the native class:

Code:
public MyNativeClass{

    void NativeFunction(MyNativeClass* _val){

         .....
         .....
         delete _val;    <------whenever this delete is called I get the assert error

     }

     ~MyNativeClass(){

          //cleans up various resources, and does so correctly even when called from the above delete

     }    <-----however upon exit of the destructor I get the assert error only if called through the delete above

};
The native class works fine if deleted from anywhere else, this is the only function in the class that tries to delete a seperate instance of itself. The reason I did it this way was because the pointer which gets passed into the function is a return value from a function in the managed class, so there is no physical pointer that I can delete outside of it. Im still learning interop, and this seemed like it would be the easiest way to plug that leak (since the return value was not getting deleted). For example:

Code:
public ref class MyMangedClass{

private:

     InternalNativePointer* _val;

     NativeClassPointer* MangedFunction(){

           MyNativeClass* _retval=new MyNativeClass();

          ......
          ......

          return _retval;

      }

      void AnotherManagedFunction(){

         InternalNativePointer->NativeFunction(ManagedFunction());      <-----the native pointer used in the native class comes from here

     }

};
The error I am getting is:

Debug Assertion Failed!

Expression _BLOCK_TYPE_IS_VALID(pHead->inBlockUse);

I tried looking through the docs, but I am not understanding why it is erroring out, am I not allowed to delete a seperate instance of the class from within the class? As I mentioned, all the other calls to delete from outside of the class work fine, and even when the specific call in question is run, it goes through the destructor fine and cleans up all the resources as it should, and I set the pointers to those resources to zero afterwards.

What am I doing wrong?

Thanks in advance,