Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WebClient.DownloadString gives first chance exception

A call to WebClient.DownloadString gives a first chance exception:

IOException: The specified registry key does not exist.

For some time now I'm recieving first chance exceptions running our software in existing code.

We have the policy that our code should run without giving first change exceptions to make debugging easier.

The first chance exception occurs in the WebClient class when calling the DownloadString and in a remoting scenario where the remote host is unavailable.

Does anyone know how we can prevent this first chance exception?

I'm running VS 2010 on a Windows 8 machine. I don't have any anti virus or firewalls running as far as I know of.

The code is running on x86 mode for the .Net framework 4.0 with debugging enabled. The code is a mix of VB.Net and C#

like image 530
CodingBarfield Avatar asked Dec 06 '12 07:12

CodingBarfield


People also ask

What does Webclient Downloadstring do?

This method retrieves the specified resource. After it downloads the resource, the method uses the encoding specified in the Encoding property to convert the resource to a String.

What happens if exception is thrown in catch block c#?

When an exception is thrown, the common language runtime (CLR) looks for the catch statement that handles this exception. If the currently executing method does not contain such a catch block, the CLR looks at the method that called the current method, and so on up the call stack.

When to use a try catch c#?

Use try / catch blocks around code that can potentially generate an exception, and your code can recover from that exception. In catch blocks, always order exceptions from the most derived to the least derived. All exceptions derive from the Exception class.


1 Answers

It's a .NET issue, Microsoft released an update here:

http://technet.microsoft.com/en-us/security/bulletin/ms12-074

You can add the registery key that is missing your self:

Registry location: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework  
DWORD (32-bit) Value name: LegacyWPADSupport
Value data: 0

and for 64bit machines:

Registry location: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\.NETFramework
DWORD (32-bit) Value name: LegacyWPADSupport
Value data: 0
like image 170
Swen Kooij Avatar answered Oct 12 '22 19:10

Swen Kooij