WebRequest throws IOException “The specified registry key does not exist.”

When you are using .NET 2.0 or .NET 3.5 and you are trying to make a web request with WebRequest class you may see the following internal error if you have Common Language Runtime Exceptions enabled during debugging in Visual Studio:

Exception thrown: ‘System.IO.IOException’ in mscorlib.dll
Additional information: The specified registry key does not exist.

To fix it, add the following registry keys into registry (.reg):

Windows Registry Editor Version 5.00
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework]
"LegacyWPADSupport"=dword:00000000
 
[HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework]
"LegacyWPADSupport"=dword:00000000
Categories: C# Tags: , , ,
%d bloggers like this: