Marshal.SizeOf() will throw an exception when trying to calculate the lenght of an object of type MyClass.
Here is the class:
<StructLayout(LayoutKind.Sequential, Pack:=1)>
Public Class MyClass
Public ReadOnly UniqueId As Long
<MarshalAs(UnmanagedType.AnsiBStr, SizeConst:=60, SizeParamIndex:=0)>
Public ReadOnly Name As String
End Class
This code will fail:
Dim MyObject = New MyClass()
Dim size = Marshal.SizeOf(MyObject) 'will throw exception here. Why?
It will throw the exception "no meaningful size or offset can be computed"
How can I get the lenght of MyObject instead?