[英]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 : 为了解决这个问题:
Desktop
folder under C:\\Windows\\SysWOW64\\config\\systemprofile
or C:\\Windows\\System32\\config\\systemprofile
(depending your OS) C:\\Windows\\SysWOW64\\config\\systemprofile
或C:\\Windows\\System32\\config\\systemprofile
下创建Desktop
文件夹(取决于您的操作系统) dcomcnfg.exe
and change the identity into the properties to The interactive user
. dcomcnfg.exe
检查Office组件的配置,并将身份更改为The interactive user
”属性。 Beware components names differ... 当心组件名称不同...
Document Microsoft Word 97-2003
Document Microsoft Word 97-2003
Microsoft Excel Application
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.