.NET - An WebClient issue related to Regsitry w...

Recently there is an issue about Win32 issue with error message like this:

<!-- lang: error -->
System.IO.IOException occurred
HResult=2
Message=The specified registry key does not exist.
Source=mscorlib
StackTrace:
     at Microsoft.Win32.RegistryKey.Win32Error(Int32 errorCode, String str)

It has been discussed here in the stackoverflow page - here: HttpClient request throws IOException

and there is a reproduce code, which is look like this:


HttpClient client = new HttpClient();
Uri uri = new Uri("http://www.google.com");
client.GetAsync(uri);

The solution is to enable the HKCU registry setting here:

<!-- lang: registry-->
Windows Registry Editor Version 5.00

; The following value prevents an IOException from being thrown and caught
; by System.Net.HybridWebProxyFinder.InitializeFallbackSettings() (in System.dll)
; when WebRequest.Create is first called.  By default the "LegacyWPADSupport"
; value doesn't exist, and when InitializeFallbackSettings calls GetValueKind,
; an IOException is thrown.  This adds the value with its default of false to
; prevent the exception.
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"LegacyWPADSupport"=dword:00000000

[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework]
"LegacyWPADSupport"=dword:00000000

你可能感兴趣的:(.net)