简体   繁体   English

InteropServices.COMException(0x800A1066):在Teamcity下命令失败

[英]InteropServices.COMException (0x800A1066): Command failed under Teamcity

I have the following code in C# 4.5. 我在C#4.5中具有以下代码。 It just writes a simple Hello world into a word document using Office 2013. 它只是使用Office 2013将简单的Hello world写入Word文档。

_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);
}

It runs without any problems under Windows 7 and Windows Server 2012 R2. 它在Windows 7和Windows Server 2012 R2下运行没有任何问题。 But when I launch it under Teamcity, on the same Windows Server 2012 R2, I expect the following errors : 但是,当我在同一Windows Server 2012 R2上的Teamcity下启动它时,我预计会出现以下错误:

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

To solve this problem : 为了解决这个问题:

  • Check this thread . 检查此线程 ie : Create Desktop folder under C:\\Windows\\SysWOW64\\config\\systemprofile or C:\\Windows\\System32\\config\\systemprofile (depending your OS) 即:在C:\\Windows\\SysWOW64\\config\\systemprofileC:\\Windows\\System32\\config\\systemprofile下创建Desktop文件夹(取决于您的操作系统)
  • Check the configuration of office component with dcomcnfg.exe and change the identity into the properties to The interactive user . 使用dcomcnfg.exe检查Office组件的配置,并将身份更改为The interactive user ”属性。

Beware components names differ... 当心组件名称不同...

  • Word : Document Microsoft Word 97-2003 Word: Document Microsoft Word 97-2003
  • Excel : Microsoft Excel Application Excel: Microsoft Excel Application

You can retrieve registered components with regedit on HKCR\\AppId . 您可以使用HKCR\\AppId上的regedit检索注册的组件。 All Office 2013 components finish by 0000-0000-C000-000000000046 Office 2013的所有组件的完成日期为0000-0000-C000-000000000046

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 InteropServices.COMException - InteropServices.COMException C# AutoIt InteropServices.COMException 错误 - C# AutoIt InteropServices.COMException error 将项目添加到 ObservableCollection 时出现 InteropServices.COMException - InteropServices.COMException when adding item to ObservableCollection System.Runtime.InteropServices.COMException(0x800A1436) - System.Runtime.InteropServices.COMException (0x800A1436) 间歇性的“ InteropServices.COMException / ForwardCallToInvokeMember”在范围单元格上访问Value2 - Intermittent “InteropServices.COMException / ForwardCallToInvokeMember” accessing Value2 on Range cell 如何在不安装Excel的情况下修复InteropServices.COMException? - How can I fix InteropServices.COMException without installing Excel? 为什么使用此代码会得到“ InteropServices.COMException / ForwardCallToInvokeMember”? - Why would I get, “InteropServices.COMException / ForwardCallToInvokeMember” with this code? com 异常 excel InteropServices.COMException - c# - com exception excel InteropServices.COMException - c# 关闭 Excel 工作簿 - System.Runtime.InteropServices.COMException:来自 HRESULT 的异常:0x800A03EC - Closing Excel Workbook - System.Runtime.InteropServices.COMException : Exception from HRESULT: 0x800A03EC System.Runtime.InteropServices.COMException(0x80030020):操作失败 - System.Runtime.InteropServices.COMException (0x80030020): The operation failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM