Here is a C# program that tries Marshal.SizeOf on a few different types:
using System;
using System.Runtime.InteropServices;
[StructLayout(Layo
It is not known what size the aggregated object T would have (it would be the size of a pointer if T is a referenece type and mostly any value if it is value type).
I think you can solve this problem by setting the MarshalAs attribute on the field 'value' specifying the most matching type (for example, Unmanagedtype.SysInt). Note that it still won't work for so-called non-mappable types (i.e. types for which fields offsets and sizes can't be deduced easily).
But AFAIK, it's not recommended to use generics in interop.