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
Du musst angemeldet sein, um einen Kommentar abzugeben.
Um dieses problem zu lösen :
Desktop
Ordner unterC:\Windows\SysWOW64\config\systemprofile
oderC:\Windows\System32\config\systemprofile
(je nach OS)dcomcnfg.exe
und ändern Sie die Identität von Eigenschaften zuThe interactive user
.Achtung Komponenten, die Namen unterscheiden sich...
Document Microsoft Word 97-2003
Microsoft Excel Application
Können Sie abrufen registrierte Komponenten mit
regedit
aufHKCR\AppId
. Alle Office 2013-Komponenten beenden von0000-0000-C000-000000000046
TC läuft nicht mit System-Konto, es hat seinen eigenen user. Die Datei-variable enthält :
Path.Combine(Directory.GetCurrentDirectory(), "test.docx");
ich habe auch versucht mitAppDomain.CurrentDomain.BaseDirectory
InformationsquelleAutor Emmanuel Chaffraix