Question

For a few weeks, I've been trying to fix an issue which appeared from nowhere. The issue is, that whenever I try to create WebRequest, it fails with a NotInitialized exception. It's not just the new code, also older apps which used to work well are now crashing at that point. I tried uninstalling .NET 2.0 SDK (which I thought might be the cause), but with no result.

Even WebClient cannot download anything, just throws unknown exception. This appears in .NET 2.0 and 3.0, .NET 4.0 and 4.5 appear to be working fine.

Does anybody know why is this happening?

EDIT: It has two possible exceptions. One is ConfigurationErrorsException (Configuration system failed to initialize), which disapears when i delete the app.config, which I don't need anyways.

The second one is NullReferenceException (Object reference not set to an instance of an object.)

StackTrace:

 at System.Net.WebRequest.get_PrefixList()
   at System.Net.WebRequest.Create(Uri requestUri, Boolean useUriBase)
   at System.Net.WebRequest.Create(String requestUriString)
   at EAC.Form1.Request(String url, String postData, Boolean useAlpha, Boolean useBeta) in D:\Projects\someproject\someproject\Form1.cs:line 34
Was it helpful?

Solution

Check "webRequestModules" section registration in machine.config, and add if it does not exist.

<sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
        <section name="authenticationModules" type="System.Net.Configuration.AuthenticationModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="connectionManagement" type="System.Net.Configuration.ConnectionManagementSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="defaultProxy" type="System.Net.Configuration.DefaultProxySection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <sectionGroup name="mailSettings" type="System.Net.Configuration.MailSettingsSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
            <section name="smtp" type="System.Net.Configuration.SmtpSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        </sectionGroup>
        <section name="requestCaching" type="System.Net.Configuration.RequestCachingSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="settings" type="System.Net.Configuration.SettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
        <section name="webRequestModules" type="System.Net.Configuration.WebRequestModulesSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
</sectionGroup>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top