AccessViolationException from WebBrowser control with custom IDownloadManager

半城伤御伤魂 提交于 2019-12-04 18:24:38

I still don't fully understand why my application was crashing, nor do I fully understand why the following code fixed it, but here's what ended up preventing the crash:

[DllImport("urlmon.dll"), PreserveSig]
[return: MarshalAs(UnmanagedType.Error)]
static extern int CoInternetSetFeatureEnabled(int FeatureEntry, [In, MarshalAs(UnmanagedType.U4)]uint dwFlags, bool fEnable);

CoInternetSetFeatureEnabled(ComInteropConstants.FEATURE_MIME_HANDLING, (uint)ComInteropConstants.SET_FEATURE_ON_PROCESS, true);
CoInternetSetFeatureEnabled(ComInteropConstants.FEATURE_MIME_SNIFFING, (uint)ComInteropConstants.SET_FEATURE_ON_PROCESS, true);

So it looks like without these features turned on (MIME handling and MIME sniffing), bad HTTP responses (content type application/octet-stream with text content) cause problems.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!