0

This Code is working fine with console application, but I am getting error with windows service saying Configuration system failed to initialize(System.Configuration.ConfigurationErrorsException was caught)

 private static async Task Backup()
    {
        using (var dbx = new DropboxClient("<REDACTED>")) 
        {
            string folder = "DropboxUpload";
            string file = "setup.exe";
            string content = @"D:\Share\setup.exe";
            log.Info("Chunk upload file...");
            // Chunk size is 100 mb.
            const int chunkSize = 2 * 1024 * 1024;
            using (var stream = new FileStream(content, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                int numChunks = (int)Math.Ceiling((double)stream.Length / chunkSize);
                byte[] buffer = new byte[chunkSize];
                string sessionId = null;
                for (var idx = 0; idx < numChunks; idx++)
                {
                    log.Info("Start uploading chunk {0}" +idx);
                    var byteRead = stream.Read(buffer, 0, chunkSize);
                    using (MemoryStream memStream = new MemoryStream(buffer, 0, byteRead))
                    {
                        if (stream.Length <= chunkSize)
                        {  
                          // here i am getting exception
                         await dbx.Files.UploadAsync(new CommitInfo("/" +folder + "/" + file), body: memStream);
                        }
                        else if (idx == 0)
                        {
                            var result = await dbx.Files.UploadSessionStartAsync(body: memStream);
                            sessionId = result.SessionId;
                        }
                        else
                        {
                            UploadSessionCursor cursor = new UploadSessionCursor(sessionId, (ulong)(chunkSize * idx));
                            if (idx == numChunks - 1)
                            {
                                await dbx.Files.UploadSessionFinishAsync(cursor, new CommitInfo("/" + folder + "/" + file), memStream);
                                log.Info("BackUp Completed...!!!");
                            }
                            else
                            {
                                await dbx.Files.UploadSessionAppendV2Async(cursor, body: memStream);
                            }
                        }
                    }
                }
            }
        }
    }

App Config file

   <?xml version="1.0" encoding="utf-8"?>
   <configuration>
   <startup>
      <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
   </startup>
   <configSections>
          <section name="log4net" type="System.Configuration.IgnoreSectionHandler" />
    </configSections>
  <log4net>
   <!-- Define some output appenders -->
      <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
      <file type="log4net.Util.PatternString" value="Logs\RIPBackupService.txt" />
    <appendToFile value="false" />
     <maxSizeRollBackups value="10" />
     <maximumFileSize value="100MB" />
     <rollingStyle value="Size" />
  <LockingModel type="log4net.Appender.FileAppender+MinimalLock" />
  <staticLogFileName value="true" />
  <layout type="log4net.Layout.PatternLayout">
    <header value="START SESSION" />
    <footer value="END SESSION" />
    <conversionPattern value="%date [%thread] %-5level %logger | %message%newline" />
  </layout>
</appender>
<!-- Setup the root category, add the appenders and set the default level -->
<root>
     <level value="ALL" />
    <appender-ref ref="RollingLogFileAppender" />
  </root>
   <logger name="Raid.LogFile">
     <level value="ALL" />
   </logger>
 </log4net>

  <system.web>
<membership defaultProvider="ClientAuthenticationMembershipProvider">
  <providers>
    <add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" />
      </providers>
    </membership>
       <roleManager defaultProvider="ClientRoleProvider" enabled="true">
    <providers>
         <add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" />
  </providers>
</roleManager>
 </system.web>
</configuration>
3
  • What is the message of the exception?
    – Chetan
    Commented May 25, 2017 at 6:46
  • System.Configuration.ConfigurationErrorsException was caught _HResult=-2146232062 _message=Configuration system failed to initialize HResult=-2146232062
    – Dutt93
    Commented May 25, 2017 at 6:48
  • [Cross-linking for reference: dropboxforum.com/t5/API-support/… ]
    – Greg
    Commented May 25, 2017 at 16:55

1 Answer 1

2

There is a duplicate key in your app settings can you check your application settings app.confg

3
  • i am not using application setting in app.config
    – Dutt93
    Commented May 25, 2017 at 6:50
  • check your App.config you will find a duplicate key or can you put your App.config in the question to see the real problem Commented May 25, 2017 at 6:57
  • put <startup> section after <configSections> Commented May 25, 2017 at 7:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.