Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6379019
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T02:05:04+00:00 2026-05-25T02:05:04+00:00

In my project, I need to automate Excel and Word at the server side

  • 0

In my project, I need to automate Excel and Word at the server side for use by clients. I ran my code in a sample console application and all works well, but inside of the WCF service, I got some errors.

My code looks like this:

var wordApp = new Word.Application();
wordApp.Visible = true;
wordApp.Documents.Add();

wordApp.Selection.PasteSpecial(Link: true, DisplayAsIcon: true); //Throws exception

var _excelApp = new Excel.Application();
_excelApp.Visible = true;

_excelApp.Worksheets.Add(); //Throws exception

And the errors are:

System.Runtime.InteropServices.COMException was unhandled by
user code
HelpLink=wdmain11.chm#24822
Message=The specified data type is unavailable.
Source=Microsoft Word
ErrorCode=-2146822946
StackTrace:
at Microsoft.Office.Interop.Word.Selection.PasteSpecial(Object&
IconIndex, Object& Link, Object& Placement, Object& DisplayAsIcon,
Object& DataType, Object& IconFileName, Object& IconLabel)
at OfficeApiPlugin.UsingOfficeApiService.DisplyWorksheet(WorksheetRow[]
worksheetData)
at SyncInvokeDisplyWorksheet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc)


System.Runtime.InteropServices.COMException was unhandled by user
code
Message=Exception from HRESULT: 0x800A03EC
Source=Microsoft.Office.Interop.Excel
ErrorCode=-2146827284
StackTrace:
at Microsoft.Office.Interop.Excel.ApplicationClass.get_Worksheets()
at OfficeApiPlugin.UsingOfficeApiService.DisplyWorksheet(WorksheetRow[]
worksheetData) in C:\Users\Mahdi7s\Documents\Visual Studio
2010\Projects\OfficeApiPlugin\OfficeApiPlugin\UsingOfficeApiService.cs:line
29
at SyncInvokeDisplyWorksheet(Object , Object[] , Object[] )
at System.ServiceModel.Dispatcher.SyncMethodInvoker.Invoke(Object
instance, Object[] inputs, Object[]& outputs)
at System.ServiceModel.Dispatcher.DispatchOperationRuntime.InvokeBegin(MessageRpc&
rpc)

How can I do this without this errors?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T02:05:05+00:00Added an answer on May 25, 2026 at 2:05 am

    I think the problem is that the clipboard (which is the operation that is blowing up) requires the use of an STA COM thread. WCF calls are performed on threadpool threads which are MTA threads.

    Spin up your own thread using the Thread class and set its ApartmentState to ApartmentState.STA and then perform your Office automation from there. The simplest thing then would be to block your WCF thread until the automation is complete.

    A couple of things to be aware of, however:

    1. If you have a lot of concurrent calls you will have to create a threadpool of STA threads rather than spin a new one up each time.
    2. For higher throughput you may want to consider making your service operation asynchronous and creating a custom IAsyncResult that signals when the automation is complete. This will allow the WCF thread to be reused while the automation is in progress.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project I need to use third party code, stored in several Git
I need to print the source code of a VS2010 project (all files, around
I need to automate office documents (Word & Excel) from my .Net4 app. Since
I am working on a project where I need to automate some workflows in
For a project I need to automate creation of business cards. Now, they have
As part of a project I'm working on, I need to automate a label
In my project I need to upload a big file (~250GB) to remote server,
I'm working on a project right now in which I need to automate animated
We are using NHibernate in our project and need all .hbm.xml files to be
I need to automate a SoapUI-project that uses HermesJMS with Maven2. The Problem I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.