none
COMException - Saving a document (Multilanguage Installed) RRS feed

  • Question

  • Good morning at all!

    I've a problem saving a word document in C#. My code was working fine until now.
    The code is developed in Visual Studio 2003 and we did test in several operative systems.
    ------------
    I found a problem with this configuration:
    *Windows Server 2008
    *Office 2007 Enterprise SP2
    *Multilanguage installed in both
    ------------

    When I do in the method 'Save':

    WordApp.Selection.Find.ClearFormatting();

    The code return me the exception 'Object referencec not set to an instance of an object'. I saw that in WordApp, in some fields like 'columns' or 'cells' or 'VBE', I can read '<error: an exception of type: {System.Runtime.InteropServices.COMException} occurred' so I suppose that I could be related.

    I looks like a Word problem. Has someone got some information about it?

    Thanks so much!



    • Edited by SScorm Monday, December 3, 2012 3:47 PM
    Friday, November 30, 2012 8:57 AM

Answers

  • We finally find that it is so important to install the applications in order.

    1º Office
    2º Multilanguage
    3º Service Pack

    We think that it's possible that MUI overwrites some dll because when you install MUI, the application stops to work fine. But when you install Service Pack it works fine again.

    So if someone has the same problem... he would have to follow the steps.

    Thanks for your time :) !!
    • Marked as answer by SScorm Tuesday, December 4, 2012 8:56 AM
    • Edited by SScorm Tuesday, December 4, 2012 8:57 AM
    Tuesday, December 4, 2012 8:56 AM

All replies

  • what is the value of Thread.CurrentThread.CurrentCulture before calling this?
    Friday, November 30, 2012 9:27 AM
  • Hi DamianD!

    I have seen in Thread.CurrentThread.CurrentCulture:

    Calendar Gregorian calendar

    Language English (United States)

    Do you need another information about it?

    Thanks for the reply

    Friday, November 30, 2012 9:49 AM
  • no, that is fine. Ok, let's start with basics, since your line contains chained objects, please break it up

    WordApp.Selection.Find.ClearFormatting();

    Selection s = WordApp.Selection;

    Find f = s.Find;

    f.ClearFormatting();

    and see what object might be null.

    Friday, November 30, 2012 10:29 AM
  • Hi DamianD!

    Neither objects are null.

    's' has several fields with the InteropService.COMException. For example 'cells', 'rows', 'columns'... have this  exception.

    Otherwise, when I try to open 'f' in the watch window, visual studio stops debugging or locked it ... so I think it could be the problem.

    Do you have another idea?

    Thaks so much for your time!

    Friday, November 30, 2012 3:16 PM
  • hard to tell from debugging since STA objects tend to deadlock quite often with debbuger injection thunks. Are you sure you are invoking this code from main UI thread?

    Friday, November 30, 2012 6:01 PM
  • <<When I do in the method 'Save':

    WordApp.Selection.Find.ClearFormatting();

    The code return me the exception 'Object referencec not set to an instance of an object'.>>

    Please show us what you mean by "When I do in the method Save...". Word's save method has nothing to do with Find...

    The other place to look for the problem is Selection. The question is, whether the current selection supports performing Find. What if you test Selection.Type before the line causing the problem - what does it return when you get the error?


    Cindy Meister, VSTO/Word MVP, my blog

    Saturday, December 1, 2012 5:37 PM
    Moderator
  • Hi DamianD and Cindy!

    Thanks for your answer. I'd try to answer your questions.

    "Are you sure you are invoking this code from main UI thread?" Yes, I'm sure because the application is not a multi-thread application.

    "Please show us what you mean by "When I do in the method Save..."" I've a 'save' method because I have to do mail merge. 

    In the code 'WordApp.Selection.Find.ClearFormatting();', I find and replace placeholders with form fields in merged document.

    This code works fine in some Operative System but whe I try to use the code in Win Server 2008 with Service Pack 2 and MUI installed, it fails.  I think that maybe it's  incompatible...

    Maybe I have to do in a different way.

    I hope that you can help me.

    Regards.

    Monday, December 3, 2012 8:07 AM
  • <<Maybe I have to do in a different way.>>

    Maybe you do, but you need to provide more information - the code, for example, where you use the line causing the problem.

    And did you check what the current Selection is, as I asked in my earlier reply?

    The problem is almost certainly with WordApp or with Selection and one of these is not being recognized as a valid object...


    Cindy Meister, VSTO/Word MVP, my blog

    Monday, December 3, 2012 8:20 AM
    Moderator
  • Hi Cindy!

    I was testing your second suggestion.

    s.Type gets 'wdSelectionIP'. I don't know if it should be correct.

    Thanks again!

    Monday, December 3, 2012 8:35 AM
  • The code related with the problem is:

    ...
    I work with the document. I do the mail merge, I remove links so on.
    ...
    object obj = Microsoft.Office.Interop.Word.WdUnits.wdStory;
    wordApp.Selection.HomeKey(ref obj, ref objMissing);
    wordApp.Selection.Find.ClearFormatting();
    wordApp.Selection.Find.Fordward=true;
    wordApp.Selection.Find.Wrap = Microsoft.Office.Interop.Word.WdFindWrap.wdFindContinue;
    ...

    Monday, December 3, 2012 9:39 AM
  • I have uninstalled German MUI and French MUI. The application continue failing but s.Find; gets an exception now.

    s.Find --> An exception of type {System.Runtime.InteropServices.COMException} occurred.

    Any idea?

    Thanks so much!
    Monday, December 3, 2012 10:41 AM
  • I have unistalled the Service Pack 2 of the Office and my application works fine.

    The problem seems to be of Office Service Pack 2.

    What can I do on the matter?

    Thanks so much!



    • Edited by SScorm Monday, December 3, 2012 11:27 AM
    Monday, December 3, 2012 11:27 AM
  • We finally find that it is so important to install the applications in order.

    1º Office
    2º Multilanguage
    3º Service Pack

    We think that it's possible that MUI overwrites some dll because when you install MUI, the application stops to work fine. But when you install Service Pack it works fine again.

    So if someone has the same problem... he would have to follow the steps.

    Thanks for your time :) !!
    • Marked as answer by SScorm Tuesday, December 4, 2012 8:56 AM
    • Edited by SScorm Tuesday, December 4, 2012 8:57 AM
    Tuesday, December 4, 2012 8:56 AM
  • Thank you very much for coming back and reporting on your findings and solution! I'm glad you were able to solve it on your own. This informtion will definitely help others with similar problems.

    I'm only sorry we were not able to contribute very much to the solution.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, December 4, 2012 10:15 AM
    Moderator
  • Indeed, thanks for reporting this.  I'll have a tester on the VSTO team look at this, to see if we can pin-point the issue and prevent such problem in the future.

    Michael Zlatkovsky | Program Manager, Visual Studio Tools for Office & Apps for Office

    Wednesday, December 5, 2012 7:07 PM
    Moderator