This project has moved. For the latest updates, please go here.

Class not exists: NetOffice.OfficeApi.Document

Oct 23, 2012 at 2:45 PM

I'm trying to convert a small piece of vba code to NetOffice. Here is my not working NetOffice VB.Net Code:

' open the template and display it
                    Dim olApp As New Outlook.Application
                    Dim newItem As Outlook.MailItem
                    newItem = olApp.CreateItemFromTemplate("c:\Outlook-Vorlage.oft")
                    newItem.Display()
                    'newItem = Nothing

'trying to get a WordEditor Object to do some bookmark substitution later on.
                    Dim doc As Outlook.Application
                    Dim docword As Outlook.Inspector
                    docword = newItem.GetInspector
                    doc = docword.WordEditor

'after successful compilation this failed in outlook and the following error pops up:
An error occured in OnAction:

Details:

Class not exists: NetOffice.OfficeApi.Document

 

It seems it could not load the Outlook.GetInspector.WordEditor property correctly. I've tested it with the import of the Netoffice.wordapi but without luck. What is wrong?

Thanks

Jens

Coordinator
Oct 25, 2012 at 9:23 AM

hey jens,

i see: docword.WordEditor is NetOffice.WordApi.Document
this is specal situation. let me explain. the core api looks for the target wrapper assembly/class. if its failed then a failback mechanism try to look for a type with the same name and dispatch id because some types are multiple defined. its forbidden in COM but microsoft do that(i dont know why).

the problem is ms word is no dependency from outlook. the core api looks for all referenced assemblies and checks for the NetOfficeAssembly attribute. and here comes the problem. the optimization! if you dont use any features from the word assembly, the clr removes the assembly reference. as hotfix you can do a dumy:

Dim dumy As NetOffice.OfficeApi.COMAddIn = Nothing

write this as first line or in any other line and the clr doesnt remove the assembly reference and it works.
good to know:
any netoffice assembly contains a list of directly references(Outlook->Office,VBEIDE) and the core api try to load these assemblies regardless from assembly references in the application domain.

i create an item on my todo list for these problem.

Sebastian


Oct 26, 2012 at 8:21 AM
Edited Oct 26, 2012 at 8:21 AM

Hi Sebatian,

this line does exactly what i need:

Dim dumy As NetOffice.OfficeApi.COMAddIn = Nothing

Thanks for your precise and outstanding fast reply.

Jens

Coordinator
Oct 26, 2012 at 8:24 AM

hey jens,

btw you dont the dumy line hm?
change your last line 
doc = docword.WordEditor
to
Dim doc As Word.Document =docword.WordEditor
because your doc variable is Outlook.Application
after changing this you dont need the dumy line because you use a wordapi type and the CLR doesnt remove the assembly reference.

Sebastian