I want to have a managed buffer as a member in mixed class:
class A {
    cli::array<Byte> m_managedBuffer;
}
This results in:
error C3265: cannot declare a managed 'm_managedBuffer' in an unmanaged 'A'
So I tried using auto_gcroot:
class A {
    auto_gcroot<cli::array<Byte> ^> m_managedBuffer;
}
And got the following error:
error C2106: '=' : left operand must be l-value
My solution is to use a managed wrapper
ref class ByteArray
{
    public:
    ByteArray(size_t size) {
          m_bytes = gcnew cli::array<Byte>(size);
    }
    cli::array<Byte> ^ m_bytes;
};
I don't like this because it introduces a level of indirection to get to the actual buffer and furthermore, when I want to pin the managed buffer (pin_ptr) - how do I do it? Can I just pin the inner m_bytes memeber without pinning the outer ByteArray object?
Solution: Use gcroot instead of auto_gcroot. The managed byte array will be cleaned up by GC, doesn't have to be under auto_gcroot.