This project has moved and is read-only. For the latest updates, please go here.

Migration Word add in code to netOffice

Mar 26, 2014 at 10:54 AM
I have com addin project developed for office 2003/07 I need to upgrade to 2010/13.
How can I migrate my code to netOffice? or I need to rewrite all/portion of code?
I can not find help in documentation!

Kind Regards
Mar 27, 2014 at 9:21 AM
Edited Apr 2, 2014 at 12:09 AM
I can't give you an answer because i need to know more details.
The 2003/2007 addin is written in VB6, or C# or VB.Net?
It's a VSTO project, or plain interop?

NO is very very similar(nearly 100%) to the standard office automation modell.
But you have to use Dispose() instead of Marshal.ReleaseComObject.
Currently, some VSTO features are missing.

(Take a look at the example projects. Typical is you can use >90% old code without changes)

Mar 28, 2014 at 6:33 AM
Project is plain interop and in C#!
I need to change some libraries or build new project?
can i get help step by step?

Kind Regards
Mar 29, 2014 at 1:54 AM
Edited Apr 2, 2014 at 12:11 AM
  1. create a backup copy(or ignore if svn,tfs,... is present)
  2. remove interop assembly references
  3. add NO assemblies( for word its: NetOffice.dll, OfficeApi.dll, VBIDEApi.dll, WordApi.dll) you find a deployment table in the [documentation])(
  4. change the reference property 'Embed Interop Types' for each NO assembly to 'false'
  5. Change your using statements, i suggest you using ' Word = NetOffice.WordApi;' and so on(you may have to change your code depending on using statements)
  6. Events in NO ends with 'Event', Change your code eg:
    app.Activate += new EventHandler(...) to app.ActivateEvent += new EventHandler(...)
    (the reason for the event annotation is some office objects use the same name for an event and a member method. this is not allowed in c# or vb and confuse some developers)
  7. Change all Marshal.ReleaseComObject(myObject) calls to
    if(null != myObject)
Thats all so far. You also have to know, NO use Enums in seperate Sub-Namespaces, for example NetOffice.WordApi.Enums or NetOffice.OfficeApi.Enums:

Moreover, its highly recommended to study the first 3 tutorials about com proxy management. A short explanation to compare the scenario is online available.
Mar 31, 2014 at 11:28 AM
Edited Mar 31, 2014 at 11:51 AM
Thank you for help :)
now one major issue I am facing is when MS Word starts, following event triggers
private CommandBar cellbar;
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode, object addInInst, ref System.Array custom)
    cellbar = (application as Word.Application).CommandBars["Fields"];
    //here application object parent type is Microsoft.Office.Interop.Word.Application
    //so I can not convert application it to Word.Application because its type is NetOffice.WordApi.Application
    //any solution to it?? or how can I get CommandBar from CommandBars?
I have also tried this
 void IDTExtensibility2.OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
                _wordApplication = new Word.Application(null, Application);
                 //but here properties of _wordApplication are not mapped! 
                 //i.e. every thing inside is null! still missing anything??
            catch (Exception exception)
Kind Regards
Apr 2, 2014 at 12:08 AM
looks good(second version) i can't pin point the problem. (are you sure, no debugger timeout or something like that?) if possible: send me a sample to public.sebastian[at] personal code if you want) i want clearify the situation for you.