[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1334
  • Last Modified:

Using Interop.Word for Synonyms

Hi All,

I have developed an application that uses MS Word to check for sysnonyms of a word. It all works fine on my local machine(win xp pro sp2). However when I ran the application on our live server(win2k) I get this error:

System.Runtime.InteropServices.COMException: Command failed

I have Office installed  on both machines.

When I check the Task Manager on the remote machine, I can see that an instance of winword.exe started.

===========code======================
Private Sub SpellCheck(ByVal text As String)
        Dim arrWords() As String
        Dim HTML As String
        Dim strSynonyms As String
        'Dim wrdDoc As Object = New Word.ApplicationClass
        Dim arrHTML As ArrayList = New ArrayList
        Dim strWord As String
        Dim wrdDoc As New Word.Application
        Dim SpellingSuggestions As Word.SpellingSuggestions
        Dim SpellingSuggestion As Word.SpellingSuggestion
        Dim Synonyms As Word.SynonymInfo

        wrdDoc.Documents.Add()
        Try

            arrWords = text.Split("/")
               For Each strWord In arrWords
                Synonyms = wrdDoc.SynonymInfo(Trim(strWord))
                If Synonyms.MeaningCount > 0 Then
                    HTML = "<table width=800  border=0 cellspacing=0 cellpadding=0><tr>" & _
                            "<td width=200 align=left valign=middle class=pagebody>" & strWord & "</td><td width=600  align=left valign=middle class=pagebody>"

                    For Each strSynonyms In Synonyms.MeaningList
                        HTML = HTML & "<input type=checkbox id=synonym name=synonym value=""" & strSynonyms & """>" & strSynonyms & "&nbsp;&nbsp;"
                    Next
                    HTML = HTML & "</td></tr><tr><td colspan=2 align=left valign=top><hr></td></tr></table>"
                End If
                If HTML <> Nothing Then
                    arrHTML.Add(HTML)
                    HTML = ""
                End If

            Next

            wrdDoc.Documents.Close()
            wrdDoc.Quit()
            With dlSynonyms
                .DataSource = arrHTML
                .DataBind()
            End With

        Catch ex As Exception
            wrdDoc.Documents.Close()
            wrdDoc.Quit()
            With lblError
                .Text = "Spell Check Function : " & ex.Message & ex.InnerException.ToString
                .Visible = True
            End With
        End Try

    End Sub
===============================================================

And I am using Imports System.Runtime.InteropServices

Any help would be much appreciated.

Thanks
Andrew
0
midasman
Asked:
midasman
  • 6
  • 4
1 Solution
 
mcdown75Commented:
Your machine is trying to access the command on the server.  You either need to install the .dll that performs this function on the server, or direct your program to access the .dll from the local machine, instead of the network.

0
 
midasmanAuthor Commented:
Thanks mcdown75 but I do have MS Office on the remote machine as well.

Could it be a problem setting the reference properties of the Interop.Word ?

BTW I am now exploring trying to use Office PIAS.


0
 
midasmanAuthor Commented:
OK tried the Office PIAs as well and getting the same error. Have to say that this is fustrating!
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
midasmanAuthor Commented:
Increasing pionts to 400  for this one.
0
 
mcdown75Commented:
My apologies.  This is a bug, but I have a link to an article that explains the resolution.  Try this:

http://www.dotnet247.com/247reference/a.aspx?u=http://www.kbalertz.com/Feedback_815633.aspx

Hope that helps.
0
 
midasmanAuthor Commented:
Thanks for that. But how do i apply it to my code?

This is what MS says:
==================
Dim obj As Object
    obj = New Project1.Class1()
    Dim inval As Object
    'Marshal the object before passing it to the method.
    inVal = New System.Runtime.InteropServices.DispatchWrapper(Nothing)
    obj.MyFunc(inval)
========================

Thanks once again.
0
 
mcdown75Commented:
I think what you want to do is this

Dim strWord as Object
strWord = new.system.runtime.interopservices.dispatchwrapper(nothing)
Synonyms = wrdDoc.SynonymInfo(Trim(strWord))

I may be wrong, but according to the article that's what it looks like.

Does your debug statement give any clue as to the exact line that the code is dying on?  If the above doesn't work, the line it dies on would be very helpful in figuring out what call is going haywire.
0
 
midasmanAuthor Commented:
Thank you mcdown75 for all your help. I have managed to get it working now on the remote server.

However another problem has come up which is the app is now not releasing the instance of Word that is creates. On my local machine no problem but on the remote machine just wont close out the instance. Bloody headache this turned out to be!

Anyway if you have any thoughts that would be great. I am awarding you the points anyway.

Thank you very much!

Andrew
0
 
mcdown75Commented:
Have you tried this?

strWord = nothing
strWord.close

That is the only thing I can see in your code that might be hanging open.  You close your data connections, but it has to be something like that which is hanging open.  At the end, start typing your variables and anything that has a .close option, do it.  See if that works.  

Do you have anything like a quick watch window that will show you what is still hanging out there?
0
 
midasmanAuthor Commented:
yeah i have tried all that and more..

wrdDoc.Quit(false,nothing,nothing)
System.Runtime.InteropServices.Marshal.ReleaseComObject(wrdDoc)
wrdDoc = Nothing

Absolutely no go. This has forced me now into trying to use an existing instance of word if it exists before creating a new one. Still working on it.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now