System.ArgumentException: source and destination length must be the same

System.ArgumentException: source and destination length must be the same

This error does not consider the use of ArrayPool

var narr = new NativeArray<byte>(16, Allocator.Temp);
var parr = ArrayPool<byte>.Shared.Rent(16);

narr.CopyTo(parr);

You should check the array size, Rent() can also return larger arrays, the parameter is just the minimum size.

So different lengths should be allowed,this is why this post exists

From the documentation:

So it does what it should and it’s not a bug.

Edit:

try out the static version NativeArray.Copy() here there are several overloads with length parameter.

NativeArray<byte>.Copy()

Is ok


8399364--1108899--upload_2022-8-29_22-33-59.png
I can’t see the description here

But there is no reason to limit the same length

You’re looking at the wrong method. The one you’re using is NativeArray.CopyTo. It’s defined here and in turn uses the versions here. Those versions expect equal lengths.

I didn’t mean NativeArray.CopyTo = Span.CopyTo
I mean NativeArray.CopyTo should behave like Span.CopyTo