c# - HttpClient request throws IOException -
the following code throws ioexception message: "the specified registry key not exist."
httpclient client = new httpclient(); uri uri = new uri("http://www.google.com"); client.getasync(uri);
this in console app in main. looks error being thrown mscorlib.dll!microsoft.win32.registrykey.win32error(int errorcode, string str). have no idea why error being thrown or how start debugging it.
edit stack trace:
at microsoft.win32.registrykey.win32error(int32 errorcode, string str)
it's 1 line , there no inner exxception etc..
the call stack is:
mscorlib.dll!microsoft.win32.registrykey.win32error(int errorcode, string str) + 0x189 bytes mscorlib.dll!microsoft.win32.registrykey.getvaluekind(string name) + 0x7f bytes system.dll!system.net.hybridwebproxyfinder.initializefallbacksettings() + 0x9e bytes [native managed transition] [managed native transition] system.dll!system.net.autowebproxyscriptengine.autowebproxyscriptengine(system.net.webproxy proxy, bool useregistry) + 0xd0 bytes system.dll!system.net.webproxy.unsafeupdatefromregistry() + 0x2c bytes system.dll!system.net.configuration.defaultproxysectioninternal.defaultproxysectioninternal(system.net.configuration.defaultproxysection section) + 0x1d8 bytes system.dll!system.net.configuration.defaultproxysectioninternal.getsection() + 0xec bytes system.dll!system.net.webrequest.internaldefaultwebproxy.get() + 0xcc bytes system.dll!system.net.httpwebrequest.httpwebrequest(system.uri uri, system.net.servicepoint servicepoint) + 0xdf bytes system.dll!system.net.httpwebrequest.httpwebrequest(system.uri uri, bool returnresponseonfailurestatuscode, string connectiongroupname, system.action<system.io.stream> resendrequestcontent) + 0x2b bytes system.net.http.dll!system.net.http.httpclienthandler.createandpreparewebrequest(system.net.http.httprequestmessage request) + 0x59 bytes system.net.http.dll!system.net.http.httpclienthandler.sendasync(system.net.http.httprequestmessage request, system.threading.cancellationtoken cancellationtoken) + 0xf4 bytes system.net.http.dll!system.net.http.httpmessageinvoker.sendasync(system.net.http.httprequestmessage request, system.threading.cancellationtoken cancellationtoken) + 0x4f bytes system.net.http.dll!system.net.http.httpclient.sendasync(system.net.http.httprequestmessage request, system.net.http.httpcompletionoption completionoption, system.threading.cancellationtoken cancellationtoken) + 0x13e bytes system.net.http.dll!system.net.http.httpclient.getasync(system.uri requesturi, system.net.http.httpcompletionoption completionoption) + 0xc bytes consoleservicetest.exe!consoleservicetest.program.main(string[] args) line 20 + 0x17 bytes c# [native managed transition] [managed native transition] microsoft.visualstudio.hostingprocess.utilities.dll!microsoft.visualstudio.hostingprocess.hostproc.runusersassembly() + 0x5a bytes mscorlib.dll!system.threading.executioncontext.runinternal(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state, bool preservesyncctx) + 0x285 bytes mscorlib.dll!system.threading.executioncontext.run(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state, bool preservesyncctx) + 0x9 bytes mscorlib.dll!system.threading.executioncontext.run(system.threading.executioncontext executioncontext, system.threading.contextcallback callback, object state) + 0x57 bytes mscorlib.dll!system.threading.threadhelper.threadstart() + 0x51 bytes [native managed transition]
it seems caused recent security update .net framework: ms12-074: vulnerabilities in .net framework allow remote code execution: november 13, 2012 (kb 2745030)
it boils down following code in web proxy resolution:
[registrypermission(securityaction.assert, read=@"hkey_local_machine\software\microsoft\.netframework")] private static void initializefallbacksettings() { allowfallback = false; try { using (registrykey key = registry.localmachine.opensubkey(@"software\microsoft\.netframework")) { try { if (key.getvaluekind("legacywpadsupport") == registryvaluekind.dword) { allowfallback = ((int) key.getvalue("legacywpadsupport")) == 1; } } catch (unauthorizedaccessexception) { } catch (ioexception) { } } } catch (securityexception) { } catch (objectdisposedexception) { } }
as can see checks specific registry key mentioned in kb article. should note exception caught internally, see because have enabled first chance exceptions in debug options of visual studio.
if want not see exception should add specified registry key value 0
:
registry location: hkey_local_machine\software\microsoft\.netframework dword (32-bit) value name: legacywpadsupport value data: 0
and 32-bit processes on 64-bit machines:
registry location: hkey_local_machine\software\wow6432node\microsoft\.netframework dword (32-bit) value name: legacywpadsupport value data: 0
Comments
Post a Comment