Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / April 2006

Tip: Looking for answers? Try searching our database.

"Object does not match target type." exception with Word 2003

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Carlos J. Quintero - 21 Oct 2003 10:35 GMT
Hi,

I have found an exception "Object does not match target type." in the
following circumstances:

- Using Microsoft Word 2003. It does not happen with Microsoft Word 2002.
- Using Reflection to manipulate Word instead of late binding (Option Strict
Off) in VB.Net

The code to reproduce the problem is:

     Dim objWordType As Type
     Dim objWordApplication As Object
     Dim colWordDocuments As Object
     Dim objWordDocument As Object

     Try
        objWordType = Type.GetTypeFromProgID("Word.Application.11")
        If Not (objWordType Is Nothing) Then
           objWordApplication =
System.Activator.CreateInstance(objWordType)
           colWordDocuments = objWordType.InvokeMember("Documents",
Reflection.BindingFlags.GetProperty, Nothing, objWordApplication, Nothing)
           ' This line causes exception "Object does not match target
type."
           objWordDocument = objWordType.InvokeMember("Add",
Reflection.BindingFlags.InvokeMethod, Nothing, colWordDocuments, Nothing)
        End If
     Catch objException As Exception
        MessageBox.Show(objException.ToString)
     End Try

It works fine with Word 2002 and this other code using late binding works
fine with Word 2003:

     Try
        objWordType = Type.GetTypeFromProgID("Word.Application.11")
        If Not (objWordType Is Nothing) Then
           objWordApplication =
System.Activator.CreateInstance(objWordType)
           colWordDocuments = objWordApplication.Documents
           objWordDocument = colWordDocuments.Add
        End If
     Catch objException As Exception
        MessageBox.Show(objException.ToString)
     End Try

I have omitted the cleanup of objects, so you will have to use the Task
Manager to kill winword.exe instances.

Note that I do not want to use a COM reference.

Any ideas?

Thanks in advance,

Carlos Quintero
Ying-Shen Yu[MSFT] - 22 Oct 2003 07:58 GMT
Hi Carlos,
Thank you for post, I've tested your code on my system, however, both code
snippets
work fine, I didn't get any exception.
I'd like to you if you are using a RTM release of Word 2003(11.5604.5606)?
If not, please tell me the detail version no.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!
Carlos J. Quintero - 22 Oct 2003 09:09 GMT
Hi Ying-Shen,

Yes, I am using RTM release of Word 2003(11.5604.5606).

Since you can not reproduce it, I will try to reproduce it on my side on
another machine. My current one is in Spanish and had installed Office 2000
and later Office XP (both in Spanish) and also Office XP Developer (in
English) and now Office 2003 (in English)... and maybe I have not installed
or uninstalled all versions correctly and maybe the machine is not as clean
as it should be.

Regards,

Carlos

> Hi Carlos,
> Thank you for post, I've tested your code on my system, however, both code
[quoted text clipped - 3 lines]
> If not, please tell me the detail version no.
> Thanks!
Ying-Shen Yu[MSFT] - 22 Oct 2003 11:20 GMT
Hi Carlos,
Thanks for you reply,
You said the machine you tested on had installed and unistalled several
verions of office,
this might be the cause.
I'll wait for result, if you still have problem on another machine, please
be free to reply it
on the group.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
You should not reply this mail directly, "Online" should be removed before
sending, Thanks!

--------------------
| From: "Carlos J. Quintero" <carlosq@NOSPAMsogecable.com>
| References: <eGCHca7lDHA.1708@TK2MSFTNGP12.phx.gbl>
<VK5X6nGmDHA.2088@cpmsftngxa06.phx.gbl>
| Subject: Re: "Object does not match target type." exception with Word 2003
| Date: Wed, 22 Oct 2003 10:09:42 +0200
[quoted text clipped - 32 lines]
| > If not, please tell me the detail version no.
| > Thanks!
Carlos J. Quintero - 23 Oct 2003 14:16 GMT
Hi Ying-Shen,

I installed yesterday Office 2003 (English) in another machine with Windows
2000 (Spanish) and uninstalled previously Office 2002 (Spanish) and I was
unable to reproduce the problem. So, it must be something specific to this
machine and its Office installations and I won?t pay more attention to it
since is not a general problem.

Thanks,

Carlos

> Hi Carlos,
> Thanks for you reply,
[quoted text clipped - 5 lines]
> on the group.
> Thanks!
Carlos J. Quintero - 30 Oct 2003 15:08 GMT
Just for the records, I uninstalled Word 2003 and the spell checker and
after reinstalling both it works fine.

Carlos Quintero

> > Hi Carlos,
> > Thanks for you reply,
[quoted text clipped - 5 lines]
> > on the group.
> > Thanks!
Jan Pichler - 29 Apr 2006 22:47 GMT
I FINALLY GOT THE SOLUTION!!

after messing around with this issue for hours, installing d*** office module-by-module, i finally found my personal ultimate reproducible solution: ironically, you just have to _remove_ the instal option 'ms word / primary .NET interop assembly' in the office 2003 setup. that's it, no reboot required, it just works :)

hope that can help!

bye

-jan

From http://developmentnow.com/g/21_2003_10_0_0_104273/Object-does-not-match-target-t
ype-exception-with-Word-2003.htm


Posted via DevelopmentNow.com Groups
http://www.developmentnow.com

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.