title: System.TypeInitializationException' occurred
body: <p>I am making application in ASP.NET MVC 5 C#.
  I am getting exception while trying to access connection string element from web.config file.</p>
  
  <blockquote>
    <p>An exception of type 'System.TypeInitializationException' occurred in
    WebPortalClient.dll but was not handled in user code</p>
  </blockquote>
  
  <p>Web.Config:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;!--
    For more information on how to configure your ASP.NET application, please visit
    http://go.microsoft.com/fwlink/?LinkId=301880
    --&gt;
  &lt;configuration&gt;  
    &lt;configSections&gt;
      &lt;!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --&gt;
      &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
      &lt;sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"&gt;
        &lt;section name="WebPortalClient.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
      &lt;/sectionGroup&gt;
    &lt;/configSections&gt;
    &lt;connectionStrings&gt;
      &lt;!--&lt;add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-WebPortalClient-20140714023603;Integrated Security=True"
        providerName="System.Data.SqlClient" /&gt;--&gt;
      &lt;add name="WebPortalClient.Properties.Settings.ConnectionString"
        connectionString="Data Source=192.168.1.141;Initial Catalog=Dishkau;User ID=saud;Password=rakeord1"
        providerName="System.Data.SqlClient" /&gt;
    &lt;/connectionStrings&gt;
    &lt;appSettings&gt;
      &lt;add key="webpages:Version" value="3.0.0.0" /&gt;
      &lt;add key="webpages:Enabled" value="false" /&gt;
      &lt;add key="ClientValidationEnabled" value="true" /&gt;
      &lt;add key="UnobtrusiveJavaScriptEnabled" value="true" /&gt;
    &lt;/appSettings&gt;
    &lt;system.web&gt;
      &lt;authentication mode="None" /&gt;
      &lt;compilation debug="true" targetFramework="4.5" /&gt;
      &lt;httpRuntime targetFramework="4.5" maxRequestLength="1048576" /&gt;
      &lt;sessionState mode="InProc" timeout="99999" /&gt;
    &lt;/system.web&gt;
  
    &lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false" /&gt;
      &lt;security&gt;
          &lt;requestFiltering&gt;
             &lt;!-- Set the maximum request size to 1GB (the value is in Bytes here) --&gt;
              &lt;requestLimits maxAllowedContentLength="1073741824" /&gt;
          &lt;/requestFiltering&gt;
      &lt;/security&gt;
      &lt;modules&gt;
        &lt;remove name="FormsAuthentication" /&gt;
  
      &lt;/modules&gt;
  
    &lt;!--&lt;modules&gt;
        &lt;add name="SingleSessionEnforcement" type="SingleSessionEnforcement" /&gt;
      &lt;/modules&gt;--&gt;
    &lt;/system.webServer&gt;
    &lt;runtime&gt;
      &lt;assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-5.0.0.0" newVersion="5.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" /&gt;
        &lt;/dependentAssembly&gt;
        &lt;dependentAssembly&gt;
          &lt;assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" /&gt;
          &lt;bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" /&gt;
        &lt;/dependentAssembly&gt;
      &lt;/assemblyBinding&gt;
    &lt;/runtime&gt;
    &lt;entityFramework&gt;
      &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" /&gt;
      &lt;providers&gt;
        &lt;provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
      &lt;/providers&gt;
    &lt;/entityFramework&gt;
  &lt;system.web.extensions&gt;
          &lt;scripting&gt;
              &lt;webServices&gt;
                  &lt;jsonSerialization maxJsonLength="1000000"&gt;
                  &lt;/jsonSerialization&gt;
              &lt;/webServices&gt;
          &lt;/scripting&gt;
      &lt;/system.web.extensions&gt;
    &lt;applicationSettings&gt;
      &lt;WebPortalClient.Properties.Settings&gt;
        &lt;setting name="UploadServiceUrl" serializeAs="String"&gt;
          &lt;value&gt;192.168.1.141:8085/lupload/&lt;/value&gt;
        &lt;/setting&gt;
        &lt;setting name="LicenseName" serializeAs="String"&gt;
          &lt;value&gt;ARL&lt;/value&gt;
        &lt;/setting&gt;
      &lt;/WebPortalClient.Properties.Settings&gt;
    &lt;/applicationSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I tried <a href="https://stackoverflow.com/questions/17132698/an-unhandled-exception-of-type-system-typeinitializationexception-occurred-in">this</a> but it was of no help.
  Please help me out.</p>