title: ServiceContractGenerator CodeDomProvider Compile Errors
body: <p>I am trying to use ServiceCodeGenerator and CodeDomProvider to dynamically create a service reference. When compiling the code using CodeDomProvider it throws the following errors.</p>
  
  <p>It looks like it is only for a specific web service. I am able to compile other web services but this one throws the compile errors below. </p>
  
  <p>Any idea how I can edit the source code or ignore the errors?</p>
  
  <blockquote>
    <p>CS0579: Duplicate 'System.CodeDom.Compiler.GeneratedCodeAttribute'
    attribute 99 CS0579: Duplicate
    'System.Diagnostics.DebuggerStepThroughAttribute' attribute 101
    CS0579: Duplicate 'System.CodeDom.Compiler.GeneratedCodeAttribute'
    attribute 191 CS0579: Duplicate
    'System.Diagnostics.DebuggerStepThroughAttribute' attribute 193</p>
  </blockquote>
  
  <p>The code is below:</p>
  
  <pre><code>Uri address = new Uri(url + "?wsdl");
          MetadataExchangeClientMode mexMode = MetadataExchangeClientMode.HttpGet;
          MetadataExchangeClient metadataExchangeClient = new MetadataExchangeClient(address, mexMode);
          metadataExchangeClient.ResolveMetadataReferences = true;
  
          //Trust all certificates
          System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) =&gt; true);
          ICredentials networkCredential = new NetworkCredential("username", "password", "domain");
          metadataExchangeClient.HttpCredentials = networkCredential;
  
          MetadataSet metadataSet = metadataExchangeClient.GetMetadata();
          WsdlImporter wsdlImporter = new WsdlImporter(metadataSet);
          Collection&lt;ContractDescription&gt; contracts = wsdlImporter.ImportAllContracts();
          ServiceEndpointCollection allEndpoints = wsdlImporter.ImportAllEndpoints();
  
          ServiceContractGenerator serviceContractGenerator = new ServiceContractGenerator();
          foreach (ContractDescription contract in contracts)
          {
              serviceContractGenerator.GenerateServiceContractType(contract);
          }
  
          // Generate a code file for the contracts.
          CodeGeneratorOptions codeGeneratorOptions = new CodeGeneratorOptions();
          codeGeneratorOptions.BracingStyle = "C";
  
          // Create Compiler instance of a specified language.
          CompilerResults compilerResults;
          using (CodeDomProvider codeDomProvider = CodeDomProvider.CreateProvider("CSharp"))
          {
  
              // Adding WCF-related assemblies references as copiler parameters, so as to do the compilation of particular service contract.
              CompilerParameters compilerParameters = new CompilerParameters(new string[] { "System.dll", "System.ServiceModel.dll", "System.Runtime.Serialization.dll" });
  
              compilerParameters.GenerateInMemory = true;
              compilerParameters.WarningLevel = 1;
  
              compilerResults = codeDomProvider.CompileAssemblyFromDom(compilerParameters, serviceContractGenerator.TargetCompileUnit);
          }
  
          if (compilerResults.Errors.Count &lt;= 0)
          {
              assembly = compilerResults.CompiledAssembly;
          }
          else
          {
              foreach (CompilerError error in compilerResults.Errors)
              {
                  Console.WriteLine(error.ErrorNumber + ": " + error.ErrorText + " " + error.IsWarning + " " + error.Line);
              }
  
              throw new Exception("Compiler Errors - unable to build Web Service Assembly");
          }           
  </code></pre>