Error The namespace declaration attribute has an incorrect 'namespaceURI': 'http://www.w3.org/2000/xmlns/'

GroupDocs.Conversion.Exceptions.GroupDocsConversionException: The namespace declaration attribute has an incorrect ‘namespaceURI’: ‘A Namespace Name for xmlns Attributes’.
—> System.ArgumentException: The namespace declaration attribute has an incorrect ‘namespaceURI’: ‘A Namespace Name for xmlns Attributes’. |
at System.Xml.XmlDocument.AddAttrXmlName(String prefix, String localName, String namespaceURI, IXmlSchemaInfo schemaInfo) |
at System.Xml.XmlDocument.CreateAttribute(String prefix, String localName, String namespaceURI) |
at System.Xml.XmlDocument.CreateAttribute(String name) |
at System.Xml.XmlElement.SetAttribute(String name, String value) |
at #=zCoiPV3t7M7c1UghvcT6ap3AOjVT0ELJ3g6Kd9Xo=.#=ztQ4SB2o=() |
at #=zx8dTZwHNpolrEvp937cJvRORy1siU2ExOXXDoIA=.#=zSVdfTtbz_pPv(XmlWriter #=zr3wKsCM=, #=z9Q3nyqNApg_ECEfcsAgwVbJwAZUPC1c48epiORA= #=zqkBxaxc=) |
at #=zx8dTZwHNpolrEvp937cJvRORy1siU2ExOXXDoIA=.#=zSVdfTtbz_pPv(Stream #=zeJjuG1M=, Int32 #=zQYUIAZI=) |
at #=zdOrWpSJLM0t5en9ceP8ZZX7xH1EeCZ0oMxnSm3o=.#=zeXXR2QQ=(#=zx8dTZwHNpolrEvp937cJvRORy1siU2ExOXXDoIA= #=z$JXRExU=, Boolean #=z_UF3Xw1ButfF) |
at Aspose.Pdf.Document.#=zpGsAIII=(#=ztwQljWiHgCGZzTGZVjCPbqa8iyCo #=zE8SMPJU=, Metadata #=z9svHNaQ=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zokFegk361pN1XJcwWVOZuqo2mQJY(Object #=zpt8b62g=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zUoi1jCOqsQqmIuExfqFE0fI=(MethodBase #=zpt8b62g=, Boolean #=z1Sele3Q=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=z_zsChgsba2liHRwnAqLIDAcSOp8XvYDJrA==(#=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4= #=zpt8b62g=, #=quxIChccWfGNvjLBPTNODSDnUa1l0DM45IqE2vYxPVEE= #=z1Sele3Q=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=z878lIqfB5xDYgBZoqo3YRBkGet3_() |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zrMzd9u2mY4JYkg_g0aTsY18qiGAt(Boolean #=zpt8b62g=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zokFegk361pN1XJcwWVOZuqo2mQJY(Object #=zpt8b62g=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zS8vkycAOLHR7u6Qj8xCCkkwq9NT0() |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zM5lo8zpbGNmw6HUvaQiizZj1XW27gPTmqMQ03xc=(Object #=zpt8b62g=, UInt32 #=z1Sele3Q=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zrMzd9u2mY4JYkg_g0aTsY18qiGAt(Boolean #=zpt8b62g=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zHQjz9b1nhL8NZa0A$WNJddMSRdKkb_O_1iSD8$humx7d() |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zsufQgOfLuwSYJ6F5h4qHtu4AL2rCk1X_4vtR_pAV4Fj7(Object[] #=zpt8b62g=, Type[] #=z1Sele3Q=, Type[] #=zReimDFA=, Object[] #=zB0nh9Tg=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zW53fdhJC5GFyapyItalgHhvisT9xKOtnDldnT5k=(Stream #=zpt8b62g=, String #=z1Sele3Q=, Object[] #=zReimDFA=, Type[] #=zB0nh9Tg=, Type[] #=zk9sF4M8=, Object[] #=zhwww1Bk=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zaOBj$YT0qIoekJeC5qOoHkY=(Stream #=zpt8b62g=, String #=z1Sele3Q=, Object[] #=zReimDFA=) |
at #=qoBJBsaciJvZHN2e5Zx95u7IDRipNvW4Wt4RnL2D4eN4=.#=zfH28mbdSFf6f5z4YpOz4TG669DwQ(Stream #=zpt8b62g=, String #=z1Sele3Q=, Object[] #=zReimDFA=) |
at Aspose.Pdf.Document.#=zaAw6FIOtIqIv(Stream #=zipxNehc=, SaveOptions #=zK$VHq5IDtBtQ) |
at Aspose.Pdf.Document.#=zzoLCnS3rrw3T(Stream #=zipxNehc=, SaveOptions #=zK$VHq5IDtBtQ) |
at Aspose.Pdf.Document.#=zLC9J6YS6p5Pa(Stream #=zYGYdRMJiE6sE, SaveOptions #=zjlBNQgs=) |
at Aspose.Pdf.Document.Save(Stream outputStream, SaveOptions options) | at  . ( , Stream , CancellationToken ) | at  . ( , Func2 , Action1 , CancellationToken ) | at  . (Func2 , Action1 , ConvertOptions , CancellationToken ) | at  .( , CancellationToken ) | at  .(CancellationToken ) |
at System.Threading.Tasks.Task.Execute() |
— End of inner exception stack trace — |

May i ask what is the cause of the error and how to prevent it?
For now, my temporary solution is to restart the IIS App Pool.

Hi @akhiong0904,

Thanks for the stack trace. We need a bit more context to look into it.

Could you tell us which GroupDocs.Conversion version and .NET version you’re on, and what the source format is? The best way for us to reproduce this would be a small sample project that shows the error, together with the document it fails on. Any details about the context would help too, for example whether the failure only shows up after the app has been running for a while and how to get it into that state.

hi @boris.katin , as i mentioned before, the error occured intermittent. Not always can reproduced from my side.

We are using .NET framework 4.8, and GroupDocs.Conversion 24.12.0
image.png (7.7 KB)

Do you have any samples code to collect the error information that i can put into my project, so next time when the error occured again, we can capture it and i can send it to you to analyze further.

Hi @akhiong0904,

Understood, intermittent issues like this are hard to catch, so let’s prepare for the next occurrence.

First, 24.12 is almost two years old. Please update to the latest release. If the error still appears there, we’ll have a version we can actually investigate.

For collecting data, two things help. The library can write its own log through ConverterSettings.Logger, and your catch block can keep a copy of the input document together with the full exception. Something like this:

using System;
using System.IO;
using System.Threading;
using GroupDocs.Conversion.Logging;

public class FileLogger : ILogger
{
  private static readonly object Sync = new object();
  private readonly string _path;
  private readonly string _prefix;

  public FileLogger(string path, string prefix)
  {
      _path = path;
      _prefix = prefix;
  }

  public void Trace(string message) => Write("TRACE", message);
  public void Warning(string message) => Write("WARN", message);
  public void Error(string message, Exception exception) => Write("ERROR", message + Environment.NewLine + exception);

  private void Write(string level, string message)
  {
      lock (Sync)
      {
          File.AppendAllText(_path,
              $"{DateTime.Now:O} [{level}] [thread {Thread.CurrentThread.ManagedThreadId}] [{_prefix}] {message}{Environment.NewLine}");
      }
  }
}

And around the conversion itself:

using System;
using System.Diagnostics;
using System.IO;
using GroupDocs.Conversion;
using GroupDocs.Conversion.Options.Convert;

string logDir = @"C:\ConversionLogs";
Directory.CreateDirectory(logDir);
var logger = new FileLogger(Path.Combine(logDir, "conversion.log"), Path.GetFileName(inputPath));

try
{
    logger.Trace("Start");
    using (var converter = new Converter(inputPath, () => new ConverterSettings { Logger = logger }))
    {
        converter.Convert(outputPath, new PdfConvertOptions());
    }
    logger.Trace("OK");
}
catch (Exception ex)
{
    logger.Error("Failed", ex);

    string failedDir = Path.Combine(logDir, "failed", DateTime.Now.ToString("yyyyMMdd_HHmmss_fff"));
    Directory.CreateDirectory(failedDir);
    if (File.Exists(inputPath))
    {
        File.Copy(inputPath, Path.Combine(failedDir, Path.GetFileName(inputPath)));
    }
    File.WriteAllText(Path.Combine(failedDir, "exception.txt"),
        $"Process started: {Process.GetCurrentProcess().StartTime:O}{Environment.NewLine}" +
        $"Input: {inputPath}{Environment.NewLine}" +
        ex.ToString());
    throw;
}

Every line in the log is tagged with the source file name, so you can follow a single conversion even when several run at the same time. Adjust the paths and options to match your code. When it happens again, please send us the failed folder and conversion.log. One thing we’d like to see in the log is whether the conversions that ran right after the first failure succeeded or failed as well, that tells us whether it’s tied to a particular document or to the state of the process.

ok, let me try first and will update you if it is happen again

Sounds good, we’ll wait for your update.