Problem Description:
C# fails to load the type "WIFI_AUTH_PARAM" from the assembly when calling Hikvision CHCNetSDK because it contains an object field at offset 0 that has been incorrectly aligned or overlapped by a non-object field.
solution:
- It is necessary to change the LayoutKind.Explicit of the entire file interface body header to LayoutKind.Auto, as follows:
[StructLayoutAttribute(LayoutKind.Auto)] public struct WIFI_AUTH_PARAM { [FieldOffset(0)] public UNION_EAP_TTLS EAP_TTLS;//WPA-enterprise/WPA2-enterpris模式适用 public UNION_EAP_PEAP EAP_PEAP; //WPA-enterprise/WPA2-enterpris模式适用 public UNION_EAP_TLS EAP_TLS; }
- Delete all [FieldOffset(0)], as follows
[StructLayoutAttribute(LayoutKind.Auto)] public struct WIFI_AUTH_PARAM { public UNION_EAP_TTLS EAP_TTLS;//WPA-enterprise/WPA2-enterpris模式适用 public UNION_EAP_PEAP EAP_PEAP; //WPA-enterprise/WPA2-enterpris模式适用 public UNION_EAP_TLS EAP_TLS; }
Normal use after modification.