InteropServices.COMException (0x800A1066): Befehl fehlgeschlagen unter Teamcity

Ich habe den folgenden code in C# 4.5. Es ist einfach schreibt einen einfachen Hello world in ein word-Dokument mit Office 2013.

_Application word = new Application();
word.Visible = false;
_Document document = word.Documents.Add();
var file = Path.Combine(Directory.GetCurrentDirectory(), "test.docx");

try
{
    document.Words.First.InsertBefore("Hello World");
    document.SaveAs(file);
}
catch (Exception e)
{
    logger.Fatal(e);
}
finally
{
    if (document != null)
    {
        document.Close();
        Marshal.FinalReleaseComObject(document);
    }
    application.Quit();
    Marshal.FinalReleaseComObject(application);
}

Es läuft ohne Probleme unter Windows 7 und Windows Server 2012 R2. Aber wenn ich starte es unter Teamcity, auf dem Windows Server 2012 R2, erwarte ich die folgenden Fehler :

System.Runtime.InteropServices.COMException (0x800A1066): Command failed
   at Microsoft.Office.Interop.Word.DocumentClass.SaveAs(Object& FileName, Object& FileFormat, Object& LockComments, Object& Password, Object& AddToRecentFiles, Object& WritePassword, Object& ReadOnlyRecommended, Object& EmbedTrueTypeFonts, Object& SaveNativePictureFormat, Object& SaveFormsData, Object& SaveAsAOCELetter, Object& Encoding, Object& InsertLineBreaks, Object& AllowSubstitutions, Object& LineEnding, Object& AddBiDiMarks)
   at Interop.HelloWorld.HelloWord.<>c__DisplayClass4.<WriteIt>b__3() in c:\TeamCity\buildAgent\work\27b855ae6e536c44\Interop\HelloWorld\HelloWord.cs:line 58
   at Interop.HelloWorld.HelloWord.WithDocument(_Application application, _Document document, Action handler) in c:\TeamCity\buildAgent\work\27b855ae6e536c44\Interop\HelloWorld\HelloWord.cs:line 72

System.Runtime.InteropServices.COMException (0x800A1066): Command failed
  at Microsoft.Office.Interop.Word.DocumentClass.Close(Object& SaveChanges, Object& OriginalFormat, Object& RouteDocument)
  at Interop.HelloWorld.HelloWord.WithDocument(_Application application, _Document document, Action handler) in c:\TeamCity\buildAgent\work\27b855ae6e536c44\Interop\HelloWorld\HelloWord.cs:line 92
  at Interop.HelloWorld.HelloWord.WriteIt(String file) in c:\TeamCity\buildAgent\work\27b855ae6e536c44\Interop\HelloWorld\HelloWord.cs:line 52
  at Interop.Program.Main(String[] args) in c:\TeamCity\buildAgent\work\27b855ae6e536c44\Interop\Program.cs:line 25

InformationsquelleAutor Emmanuel Chaffraix | 2014-03-21

Schreibe einen Kommentar