The default delegate calling convention is stdcall on x86, but the bundled version of curl was compiled to expect cdecl callbacks. As a result simple usage of CurlHttpWebRequest throws AVs in 32-bit.
Adding [UnmanagedFunctionPointer(CallingConvention.Cdecl)] to each callback delegate fixes it.
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr ReadFunctionCallback(IntPtr buffer, UIntPtr size, UIntPtr nItems, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate UIntPtr WriteFunctionCallback(IntPtr data, UIntPtr size, UIntPtr nMemb, IntPtr userData);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int ProgressFunctionCallback(IntPtr clientP, double dlTotal, double dlNow, double ulTotal, double ulNow);```
The default delegate calling convention is stdcall on x86, but the bundled version of curl was compiled to expect cdecl callbacks. As a result simple usage of CurlHttpWebRequest throws AVs in 32-bit.
Adding [UnmanagedFunctionPointer(CallingConvention.Cdecl)] to each callback delegate fixes it.