C# Word 2010 Documents.Open(...) only works while debug RRS feed

  • Question

  • Hi,

    we are migrating from Office 2003 to Office 2010 and do have problems with "Documents.Open(...)" in C#.

    Every file I try to open results in "Befehl misslungen".

    Referenced Microsoft.Office.Interop.Word.dll is 14.0.4762.1000

    SP1 for Office 2010 is installed. 

    .NET target-framework is v2.0.50727.


    This is a part of the Code we use:


    /// <summary>
    /// Word-Applikation
    /// </summary>
    private Word.Application _App;
    /// <summary>
    /// Aktuelles Dokument
    /// </summary>
    private Word.Document _Doc;
    private void TestApp(string pFilename)
       _App = new Word.ApplicationClass();
       _App.Visible = true;
       object filename = (object)pFilename; 
       // This is causing an exception, but ONLY if not in debug mode!!!
       _Doc = _App.Documents.Open(ref filename, ref _Missing, ref    _Missing, ref _Missing, ref _Missing,
                                               ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _Missing,
                                               ref _Missing, ref _Missing, ref _Missing, ref _Missing, ref _Missing);


    I tested several locations for the file to open, e.g. C:\TEMP. I made C:\TEMP a trusted path in security center of word 2010 and gave myself full access to the file. But nothing works.

    Only while debugging, it works!

    The PC is in a Domain, the normal.dotm belongs to a mapped drive for personal documents.

    Any hint on solving this would be great!

    Btw., we have Office 2003 AND Office 2010 installed! But the error is also present on machines where only Office 2010 is installed.

    • Edited by place2be Monday, September 5, 2011 8:31 AM
    Monday, September 5, 2011 8:28 AM


All replies

  • Hm, strange things...

    For testing purpose, I now used this Code in a new C#-Project:


    On my PC, it does not work with the same Exception as above. On another PC, same Office-Installation (2003+2010) it works.

    Now, I put a Thread.Sleep(500); before the Documents.Open-Function... and it works! But why?

    Monday, September 5, 2011 9:46 AM
  • This might be better suited for a C# forum.
    If you found this post helpful, please "Vote as Helpful". If it answered your question, remember to "Mark as Answer".

    Rich Prescott | MCITP, MCTS, MCP

    [Blog] Engineering Efficiency | [Twitter] @Rich_Prescott | [Powershell GUI] Client System Administration toolkit
    • Marked as answer by place2be Tuesday, September 6, 2011 6:04 AM
    Monday, September 5, 2011 12:39 PM
  • I did not know where to address the problem, because it does not seem to be a problem of Visual Studio and C#.

    But I posted the topic somewhere else. thx.

    Tuesday, September 6, 2011 6:05 AM