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 526205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:45:06+00:00 2026-05-13T08:45:06+00:00

Update : This is a confirmed bug in Silverlight 4 beta. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523052 I solved

  • 0

Update: This is a confirmed bug in Silverlight 4 beta. http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=523052

I solved this issue by switching to a full blown WPF application and using regular old Microsoft.Office.Interop.Word. But I’m still very interested in how to get this to work using the dynamic values from ComAutomationFactory.

This may be more of a C# 4.0 question, but what I’m trying to do is leverage the ComAutomationFactory class in a trusted SL4 app to load up a Word doc, change some text, and print it.

Using a regular windows app, it’s pretty easy:

  Object oMissing = System.Reflection.Missing.Value;
    Object oTrue = true;
    Object oFalse = false;

    Application oWord = new Application();
    Document oWordDoc = new Document();

    oWord.Visible = false;

    object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
    oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);

    foreach (Field myMergeField in oWordDoc.Fields)

However, in SL4 you have to use the dynamic keyword. It works fine until I try to iterate over my fields:

    Object oMissing = System.Reflection.Missing.Value;
    Object oTrue = true;
    Object oFalse = false;

    dynamic oWord = ComAutomationFactory.CreateObject("Word.Application");

    oWord.Visible = false;

    object oTemplatePath = "C:\\Users\\jwest\\Desktop\\DocumentTemplate.dotx";
    dynamic oWordDoc = oWord.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
    dynamic fields = oWordDoc.Fields;

    foreach (var myMergeField in fields)

In which case I get a runtime error saying that I cannot implicitly convert a ComAutomationMetaObjectProvider to IEnumerable. No matter what I do, any properties related to my Word com object are of type ComAutomationMetaObjectProvider and I cannot iterate over them.

It has been mentioned that I should try getting the field as a String from a member.

        for (int i = 0; i < oWordDoc.Fields.Count; i++)
        {
            String field = oWordDoc.Fields.Item[i].Result.Text;
        }

This results in an interesting exception of: HRESULT: 0x800A16E6 which when Googled, brings up absolutely nothing.

  • 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-13T08:45:06+00:00Added an answer on May 13, 2026 at 8:45 am

    It certainly isn’t a C# issue – VB.NET has the same issue. There is either a bug here or something not documented, but in either case, it seems impossible to declare collection objects.

    There is another way around this however, it is to access the individual members of the collection. Here’s a sample (in VB.NET) that allows you to iterate through via Fields.Item. (no error checking or shutting down of Word here; my .dotx has two fields – 1) date and 2) author).

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim wrd As Object = ComAutomationFactory.CreateObject("Word.Application")
        Dim path As String = "C:\Users\me\test.dotx"
        Dim wordDoc As Object = wrd.Documents.Add(path)
        Dim fieldsCount As Integer = wordDoc.Fields.Count
        Dim fieldResults As String = Nothing
        For i As Integer = 1 To fieldsCount
            fieldResults = fieldResults & " " & wordDoc.Fields.Item(i).Result.Text & vbNewLine
        Next
        TextBox1.Text = "Field Results: " & fieldResults
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 297k
  • Answers 297k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer after much trouble i came to find that -(BOOL)canBecomeFirstResponder {… May 13, 2026 at 7:17 pm
  • Editorial Team
    Editorial Team added an answer As you can see in the documentation find returns an… May 13, 2026 at 7:17 pm
  • Editorial Team
    Editorial Team added an answer I fail to see what is wrong with using a… May 13, 2026 at 7:17 pm

Related Questions

Update: This bug has been confirmed by at least two others. Even if you
WPF is promising us a lot of niceties, but some of them don't live
I'm using PHP 5.3.0 and have encountered something that might be a bug (in
I am using JPA with Hibernate underneath, and I am having trouble getting merge
I have to deal with a table where there is a set of fields

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.