ServerDocument.AddCustomization NullReferenceException

I'm trying to attach managed code to a Word document.  I've came across a weird behaviour.  When trying to customize a document which have been customized in the past, it works fine.  For brand new documents, I get a NullReferenceException.

I use the following code to customize the document:

                Assembly assembly = Assembly.LoadFile(new FileInfo(args[1]).FullName);
                string version = assembly.GetName().Version.ToString();
                FileInfo thisAssem = new FileInfo(new Uri(assembly.CodeBase).LocalPath);

                try {
                    if (ServerDocument.IsCustomized(args[0])) {
                        ServerDocument.RemoveCustomization(args[0]);
                    }
                    ServerDocument.AddCustomization(args[0], args[1], "", version, true);
                }
                catch (Exception ex) {
                    Console.WriteLine("Cannot customize document.");
                    PrintException(ex);
                    return;
                }

I get this error on the deployment target machine:

System.NullReferenceException: Object reference not set to an instance of an obj
ect.
   at Microsoft.Office.Tools.OfficeAppInfoDocument.WriteItem(String element, String id, Byte[] item)
   at Microsoft.VisualStudio.Tools.Applications.Runtime.AppInfo.WriteManifest(IAppInfo appInfo, String manifest)
   at Microsoft.VisualStudio.Tools.Applications.Runtime.Customizer.CustomizeDocument()
   at Microsoft.VisualStudio.Tools.Applications.Runtime.Customizer.Customize()
   at Microsoft.VisualStudio.Tools.Applications.Runtime.ServerDocument.AddCustomization(String documentPath, String assemblyName, String deploymentManifestPath,
 String applicationVersion, Boolean makePathsRelative)

The odd thing is, this bit of code works on my development machine.  On the deployment target system, I have Office 2003 SP2, VSTOR, Office2003PIA.  On the development machine, I've got VS.NET 2005 b2 installed, and Office 2003 SP1 instead of SP2.  But I don't think this could cause the problem.

Any hints to why

Thanks in advance,



Answer this question

ServerDocument.AddCustomization NullReferenceException

  • jonam

    There should also be VSTOPersist.dll. Copy it over as well and run regsvr32 on it.

  • Sean G.

    This is beta2, right We forgot to ship one DLL that is required for this scenario to work. Should be fixed in the latest CTP.

  • Vidya.B

    Yes this is Beta2.

    In regards to DLL's shipped, I've had problems with the assembly VSTOPersist.Interop.dll.  I found this DLL to be installed on my development machine, but not if you just install the VSTORuntime.  I've manually packaged this file in a MSI to be registered in the GAC, however, this still doesn't not address this NullReferenceException problem.

    Is this another DLL which should have been packaged in the runtime


  • ServerDocument.AddCustomization NullReferenceException