문제

Is it possible to use Marshal.SizeOf() on a structure which is using a custom marshaler?

For example:

struct Abcde { 
  public int test1;
  [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(MyCustomMarshaler)]
  public string customString1;
}

If I call:

var size = Marshal.SizeOf(typeof(Abcde));

an exception is thrown which says that no meaningful size or offset can be computed. I noticed that ICustomMarshaler has a method called GetNativeDataSize() but the exception is thrown regardless what I return there.

도움이 되었습니까?

해결책

Marshal.SizeOf cannot be used with types that contain custom marshaled members.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top