C# calling Hikvision CHCNetSDK failed to load the type "WIFI_AUTH_PARAM" from the assembly because it contains an object field at offset 0...

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:

  1. 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; 
     }

  2.  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.

Guess you like

Origin blog.csdn.net/baidu_38493460/article/details/130851866