none
Share documents between two versions of a dok-level customization. RRS feed

  • Question

  • Hello

    We have made a doc-level customization using Word 2003 and VSTO SE for a customer. Now the customer likes to move ahead and upgrade the customization to Word 2010 and VSTO 4.0. For various reasons the users base won't move to Word 2010 all at once, so both version of our customization will live in user land.

    How can users share documents using different versions of the customization? My initial approach was to use ServerDocument to remove the customization when it is a different version,  and then add the right version of the customization. But I run into the problem that ServerDocument is version specific. So for example if I try to instanciate ServerDocument (the VSTO 4.0 version) with a document with the old customization, I get the UnknownCustomizationFileException. 

     

    Unhandled Exception: Microsoft.VisualStudio.Tools.Applications.Runtime.UnknownCustomizationFileException: Could not create a persistence object for the specified file.
       at Microsoft.VisualStudio.Tools.Applications.AppInfoDocumentFactory.GetAppInfoDocument(String documentPath, Byte[] bytes, FileAccess access)
       at Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access, Boolean throwOnPreviousVersion)
       at Microsoft.VisualStudio.Tools.Applications.ServerDocument.GetCustomizationVersion(String documentPath)
    

    I haven't tried the other way around, but I'm sure it isn't any better.

    Do I really need to have both vsto runtime installed on every client machine, and then select the right version of ServerDocument to instanciate? (can I install both vsto runtime versions in parallel at all?) or is there a better way to handle this issue?

    Best regards,

    Terje

     

     

     

     

    Thursday, July 21, 2011 12:26 PM

Answers

  • Hello again

    I think I have found the root of the problem. The ServerDocument object in VSTO 4 cannot handle the Word 97/2003 compatibility xml file format.

    This is what I tried:

    I created a simple document-level customization.

    With the code from this page How to: Attach Managed Code Extensions to Documents I first tried to attach my customization to a plain Word 2010 document saved in docx format. That went just fine.

    Then I used the same procedure to try and attach my customization to a plain Word 2010 document saved in the Word 97/2003 compatibility xml file format. This fails with the UnknownCustomizationFileException.

    Microsoft.VisualStudio.Tools.Applications.Runtime.UnknownCustomizationFileException was unhandled by user code
     Message=Could not create a persistence object for the specified file.
     Source=Microsoft.VisualStudio.Tools.Applications.ServerDocument
     StackTrace:
        at Microsoft.VisualStudio.Tools.Applications.AppInfoDocumentFactory.GetAppInfoDocument(String documentPath, Byte[] bytes, FileAccess access)
        at Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access, Boolean throwOnPreviousVersion)
        at Microsoft.VisualStudio.Tools.Applications.ServerDocument.GetCustomizationVersion(String documentPath)
    

    Do anyone know if there is any other way to attach a customization to a document?

    Best regards,

    Terje

    • Marked as answer by Terje Nagel Friday, August 12, 2011 7:04 PM
    Tuesday, August 9, 2011 11:15 AM

All replies

  • Hi Terje,

    Do you mean that you want to use VSTO 4.0 for the Word 2003 document? If I have misunderstood you, just let me know. 

    As far as I know, when creating the document level application via the wizard, we can copy  a existing document, then we can choose the word 2003 file. If so, it will the vsto runtime is 4.0 and document format is word 2003.

    Hope this idea can give you some hint and you can take a try. Wish you a nice day.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, July 25, 2011 3:12 AM
  • Hi Terje,

    How about the problem on your side? If you still need any assistant, just feel free to let us know.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, July 29, 2011 4:11 AM
  • Hi Bruce

    My problem is like this. I have two version of a document-level customization which are functionally identical, but build against two different versions of VSTO. One for VSTO 2005 SE (Word 2003) and one for VSTO 4.0 (Word 2010). If I open a document, which is created with the VSTO 2005 SE version, on a machine with the new version installed (VSTO 4.0 and office 2010) it fails to load the customization.

    I use the Word xml file format for saving the documents, and it seems that Word uses two different ways to save the reference to the cusumization, in the two different versions of VSTO.

    It is not an option to migrate all existing document to the new version, because not all users will be using the new version all at once. So I need to be able to do it runtime.

    Best Regards,

    Terje

    Monday, August 1, 2011 8:20 AM
  • Hi again

    Based on Bruces first reply I tried this:

    1) Create a new "Word 2010 template" project and in the wizard I selected my old Word 2003 .dot file as the document for my application.

    2) Added an ActionPane to the project with a label so that I could see that the customization had been loaded.

    3) Build, Publish and installed the new customization.

    4) Opened a document which was created with the old customization.

    It fails to load the assembly and I would somehow have been surprised if it did. I mean how are Word to know that the assembly reference in the old document is supposed to use a new assembly?

    This is the exception i get:

    Customization could not be loaded because the application domain could not be created.
    
    
    ************** Exception Text **************
    Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateCustomizationDomainException: Customization could not be loaded because the application domain could not be created.
      at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManagerInternal.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization& executor)
      at Microsoft.VisualStudio.Tools.Applications.Runtime.AppDomainManager.CreateCustomizationDomain(String applicationDomainPath, String documentName, IHostServiceProvider hostCallback, IExecuteCustomization& executor)
    

     

    Best regards,

    Terje

    Tuesday, August 2, 2011 7:52 AM
  • Hi Terje,

    We are doing the research about the problem. There might be some delay about the response. Appreciate your patience.

    Best Regards,


    Bruce Song [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, August 3, 2011 9:41 AM
  • Hi Terje,

    The VSTO SE customization can work for Word 2010 with some limitations. None of the new features of Office 2010 can be taken advantage of,  so you won’t be able to manipulate the elements of the Office Ribbon, and method calls to CommandBar components won’t work, since Word 2010 does not have commandbar controls.

    As you have discovered, the VSTO 4 customization doesn’t work with Word 2003. There are several reasons for that, including that VSTO 4 uses .NET Framework 3.5 or 4.0. If the latter, it doesn’t know about PIAs for Word 2003 – it uses the new system interfaces of Office 2010 instead of interop assemblies.

    The question you asked – can you have the VSTO SE customizations installed side-by-siide with the VSTO 4 customization? Yes, but when the end-user upgrades to Word 2010 the VSTO 4 customization will need to be re-installed in order to correct the registry.

    As cumbersome as it will be, you will be better served to have two different VSTO add-ins and install the VSTO 4 version when the end-user converts from Office 2003 to Office 2010.

    There is a host of content on the matter, so you could consider browsing through some or all of the following.

    Visual Studio Tools for Office Runtime Overview
    http://msdn.microsoft.com/en-us/library/bb608603.aspx

    Misha Shneerson - Site Home - MSDN Blogs
    http://blogs.msdn.com/b/mshneer/

    In that blog index, see the link to the Andrew Whitechapel blog titled:
    “Add-ins for Multiple Office Versions without PIAs”

    In the same Misha Shneerson site page see also the link to:
    Design of VSTO 2010 runtime where he explains the NoPia mode included in the .NET framework 4.0

    In response to the error message you got “CannotCreateCustomizationDomainException” see
    VSTO 2008 Throws CannotCreateCustomizationDomainException when ...
    http://blogs.msdn.com/b/vsod/archive/2008/11/01/vsto-2008-throws-cannotcreatecustomizationdomainexception-when-microsoft-word-math-add-in-is-installed.aspx

    This mentions the COM Shim wizard. For more details on COM Shim wizard please refer to (<http://msdn.microsoft.com/en-us/library/bb508939.aspx>)

    Also with regard to “CannotCreateCustomizationDomainException”
    In certain situations when Visual Studio 2010 is installed on a machine without the .Net Framework 3.5 installed, the VSTO Runtime will only be partially installed.  This causes the error.

    The resolution is to install the .Net Framework 3.5 before installing Visual Studio 2010.  If Visual Studio 2010 is already installed on the machine, install the .Net Framework 3.5 runtime and then repair the VSTO Runtime.

    Or you may be getting this error because the network location from where you are opening the document is not in the Office Trusted Location List.

    Please let us know the results of your research and your decision about whether you’ll have two different VSTO solutions.

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    Thursday, August 4, 2011 8:38 PM
    Moderator
  • Hello Chris

    Thank you for your answer.

    I think I'll have to do a better job of what I'm trying to accomplish. I just skipped to the actual problem without providing a proper background. Sorry for that.

    As you state I'm better served to have two different versions of the customization, one for Word 2003 and on for Word 2010. That is also what my goal is, and precise for the reasons you state (the bit about running side-by-side was referring to the VSTO runtime, not the customization). So in essence I would like to migrate the functionality of the old customization to a new one which is targeting Word 2010 (using VSTO 4.0 and .net 4.0)

    What I am doing is this: I create a new solution with the "Office 2010 template" wizard in Visual Studio. Then I copy the code from the old solution to the new one, and then deal with the differences like toolbars and stuff.

    All in all this works just fine. The trouble arise when I try to open a document created with the old version of the customization (the one using Word 2003 and VSTO SE), on a machine with the new one (Word 2010 and VSTO 4.0), and I suspect that doing it the other way around will cause trouble too (but I haven't tried it yet). It is important that the two versions of the customization can operate in "parallel". Not on one machine, but so that different users can have different versions installed and still share and work on the same document.

    How is the situation of opening a document, with a reference to a different version of a customization than the installed one, supposed to be handled? 

    We use the WordML xml file format for storing, so one workaround might be that we remove the reference to the customization in the xml document, and then attach the customization installed on the local computer, but it is not a particular nice solution.

    Best regards,

    Terje

     

     

    Monday, August 8, 2011 8:18 AM
  • Hello Terje,

    The problem you’re seeing results from VSTO SE creating an application-level customization associated with Word 2003. VSTO SE couldn’t create a customization for a specific document – a limitation that was fairly-well stated in the available content about SE.  It would only generate a managed-code add-in.  So the template is calling for a customization associated with Word 2003.  On a Word 2010 installation that add-in is missing.
    A document-level customization travels with the document. It is a managed-code extension for the document.  If you use VSTO 4 to create an Application-level customization for Word 2010 it is an add-in. That add-in won’t be available on a Word 2003 system.  Either way, the original Word 2003 document can’t find the customization from VSTO 4, while Word 2010 can’t find the customization originating form VSTO SE that is specified in the .dot template.

    Once the document is open/edited in Word 2010 and benefits from the functionality of the VSTO 4 customization, unless the document is saved in Word 97/2003 compatibility mode that document isn’t usable in Word 2003. That makes it impractical for the same document to be read or edited by users who aren’t using the same version of Word.

    Hopes this helps.
    Regards,
    Chris Jensen
    Senior Technical Support Lead

    Monday, August 8, 2011 10:02 PM
    Moderator
  • Hello Chris,

     

    I don't see where the application-level customization comes into the picture. The two customizations in question, are both document-level customizations.

    I agree that a document-level customization travels with the document, but it is not all the managed code assemblies which are embedded in the document, only a reference to the assemblies in the form of an ocx control embedded in the document. And that is why I am wondering how a VSTO 4.0 doc-level customization are supposed to open a document with a VSTO SE doc-level customization in the general case.

    It can't be that a document gets stuck in time, because it is made with a doc-level customization, and can't be opened in newer versions of Word. My guess would be that one had to remove the old VSTO SE customization, and attach the new VSTO 4 customization, before opening the document in Word 2010. The trouble then is how to do that from managed code? The ServerDocument object can't do that, because it is version specific.

    We do use the Word 97/2003 compatibility xml format for saving documents, in both customizations.

    Best regards,

    Terje

    Tuesday, August 9, 2011 9:33 AM
  • Hello again

    I think I have found the root of the problem. The ServerDocument object in VSTO 4 cannot handle the Word 97/2003 compatibility xml file format.

    This is what I tried:

    I created a simple document-level customization.

    With the code from this page How to: Attach Managed Code Extensions to Documents I first tried to attach my customization to a plain Word 2010 document saved in docx format. That went just fine.

    Then I used the same procedure to try and attach my customization to a plain Word 2010 document saved in the Word 97/2003 compatibility xml file format. This fails with the UnknownCustomizationFileException.

    Microsoft.VisualStudio.Tools.Applications.Runtime.UnknownCustomizationFileException was unhandled by user code
     Message=Could not create a persistence object for the specified file.
     Source=Microsoft.VisualStudio.Tools.Applications.ServerDocument
     StackTrace:
        at Microsoft.VisualStudio.Tools.Applications.AppInfoDocumentFactory.GetAppInfoDocument(String documentPath, Byte[] bytes, FileAccess access)
        at Microsoft.VisualStudio.Tools.Applications.ServerDocument.Initialize(Byte[] bytes, String documentPathOrFileType, FileAccess access, Boolean throwOnPreviousVersion)
        at Microsoft.VisualStudio.Tools.Applications.ServerDocument.GetCustomizationVersion(String documentPath)
    

    Do anyone know if there is any other way to attach a customization to a document?

    Best regards,

    Terje

    • Marked as answer by Terje Nagel Friday, August 12, 2011 7:04 PM
    Tuesday, August 9, 2011 11:15 AM
  • Hello Terje,

    ServerDocument is new to VSTO 4 and Office 2010.  The customization is recorded in an XML part which is packaged as part of the document zip.  Customization for Office 97/2003 is in the form of an ActiveX control.  VSTO working with Visual Studio 2005 and previous versions doesn’t/didn’t know about XML documents, so it won’t build a customization for Office 2007 or Office 2010.

    I believe you can see the problem with saving a Word file, be it .doc or .docx, which can be successfully edited with either version of Word. If you build a customization for a Word 2010 document, then save it as a Word 97/2003 .doc the customization (xml part) will be stripped, but no ActiveX control will be generated to replace the customization.

    Word 2003 won’t open a Word 2010 .docx (xml) document.

    Word 2010 won’t load the ActiveX customization of a Word 2003 .doc document.

    Conceptually you could build an IDTExtensibility COM add-in for Word that would store in a database the data now stored in the VSTO customization. In VBA you could use macros to retrieve into the document, and store data from the document into the database.  The COM add-in could be created in VB .NET or C# while completely sidestepping VSTO.

    If this appears to be acceptable as a solution for your client’s situation, query  Microsoft VKB specifying the KB and bing databases using the arguments “COM add-in” and Word 2010 to find content about building and installing application-level add-ins.

    Please share with us your plans and direction.

    Regards,
    Chris Jensen
    Senior Technical Support Lead


    Tuesday, August 9, 2011 6:07 PM
    Moderator
  • Hello Chris,

    I take it that you mean that there is a new version of ServerDocument in VSTO 4, because the class has been there since at least VSTO SE, if not before. It  has changed namespace since VSTO SE though, but the purpose of the class is still the same.

    When I'm talking about the "Word 97/2003 compatibility xml format" I mean the file format that ends in .xml (not the .docx file format which, I know, is also xml based)

    Word has since, at least Office 2003, supported an xml file format often referred to as "WordprocessingML" or "Office 2003 xml". It looks something like this in the start of the xml file:

    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <?mso-application progid="Word.Document"?>
    <w:wordDocument xmlns:aml="http://schemas.microsoft.com/aml/2001/core" xmlns:wpc=" ... 
    


    This is the file format we use with our VSTO SE customization, because is makes further server side handling of the document more convenient.

    Word 2010 does support the .xml file format, both in loading and saving documents, this is not the trouble. Trouble first begin, when we try to attache the VSTO 4 customization to a document saved in the .xml file format. The file format is supported in the VSTO SE version of the ServerDocument class.

    In the file "C:\Program Files\Reference Assemblies\Microsoft\VSTO40\v4.0.Framework\Microsoft.VisualStudio.Tools.Applications.Runtime.v9.0.xml" the explanation of the UnknownCustomizationFileException is as follows:

    The exception that is thrown when you pass a file with an extension that is not supported by Office development tools in Visual Studio to a <see cref="T:Microsoft.VisualStudio.Tools.Applications.ServerDocument" /> constructor or method.
    

    which clearly indicates that the file format is not supported. This is kinda strange and very unfortunate, especially because when I create a new document in Word 2010 using our VSTO 4 customization, and saves it in the .xml format, the document clearly has a reference to the customization. When I open the document again in Word 2010, Word will also happily load our VSTO 4 customization. And in the xml file the AssemblyLocation and AssemblyName custom properties has the values as they should. This is what it looks like in the xml file:

    <o:CustomDocumentProperties>
     <o:_AssemblyLocation dt:dt="string">WordTemplate1.vsto|9cdefa82-af16-4d94-b7d3-bcf9cb6231e1</o:_AssemblyLocation>
     <o:_AssemblyName dt:dt="string">4E3C66D5-58D4-491E-A7D4-64AF99AF6E8B</o:_AssemblyName>
    </o:CustomDocumentProperties>
    

    At the moment I'm fiddling with the possibility to add the AssemblyLocation and AssemblyName programmatically prior to opening the document in Word 2010. 

    Another option I'm going to look into, is to convert the .xml document into .docx before opening it, and then save it as .xml when the user are done editing it. 

    I don't think the IDTExtensibility and a database is a solution for us. Our customization doesn't store any data as such, it is more of a tool for the user, to help him write a document which must have a very specific structure (an xml structure in fact).

    Best regards,

    Terje

    Friday, August 12, 2011 12:02 PM
  • Hello Terje,

    Ah – the .xml file format, not the document (.doc or .docx) format. Please accept my apology for not having picked up on that from what you already said in this thread.

    Your ‘fiddling’ sounds like productive research. Good luck with it.

    If that avenue doesn’t resolve your need, because of the complexity of the issue it requires a more in-depth level of support provided by Microsoft paid support.  Please visit the below link to see the various paid support options that are available to better meet your needs. http://support.microsoft.com/default.aspx?id=fh;en-us;offerprophone

    Regards,
    Chris Jensen
    Senior Technical Support Lead

    Friday, August 12, 2011 2:48 PM
    Moderator
  • Hello Chris

    That's quite all right. Thank you for taking time to reply to the thread.

    Regards,

    Terje

    Friday, August 12, 2011 7:05 PM