2017-05-25 3 views
0

Ce code fonctionne correctement avec l'application console, mais une erreur est survenue dans le service Windows indiquant que le système de configuration n'a pas pu s'initialiser (System.Configuration.ConfigurationErrorsException a été intercepté)System.Configuration.ConfigurationErrorsException a été intercepté lors du chargement du fichier dans la boîte de dépôt en utilisant le service Windows

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 fichier de configuration

<?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> 
+0

Quel est le message de l'exception? –

+0

System.Configuration.ConfigurationErrorsException a été capturé _HResult = -2146232062 _message = système de configuration n'a pas pu initialiser HResult = -2146232062 – Dutt93

+0

[Réticulation de référence: https://www.dropboxforum.com/t5/API-support/ Configuration système-ConfigurationErrorsException-was-caught/mp/222830 # M11947] – Greg

Répondre

1

Il y a une clé en double dans vos paramètres de l'application, vous pouvez vérifier vos paramètres d'application app.confg

+0

Je n'utilise pas le paramètre d'application dans app.config – Dutt93

+0

Vérifiez votre App.config vous trouverez une clé en double ou pouvez-vous mettre votre App.config dans la question pour voir le vrai problème –

+0

mettre section après