fbpx
Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1

TOPIC:

COMException when trying to start Ms Word through COM Interop 30 Apr 2020 15:08 #14306

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello XSharp people.

    I would like to run an MS Word Macro within my X# Winforms app but the attempt to open any word document crashes miserably with a FatalExecutionEngineError exception (screenshot attached).The exception is System.ExecutionEngineException with HRESULT =-2146233082.

    The critical command is

    MakroDoc := WordApp:Documents:Open(dotmPfad)

    when I try to open an existing document file.

    This used to work before with X# and it still works perfectly within a simple C# app on the same computer with the same Ms Word installed etc. So 32- or 64 bit should not be an issue.

    I am using Bandol 2.32 on Windows 10 1809.

    I know this is a very general error message and its probably guessing what the reason might be but may be this kind of error could have a specific reason.

    Kind regards,
    Peter

    PS: Would it be possible to provide the X# assemblies only instead of a msi installer as well?
    Attachments:

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 30 Apr 2020 15:19 #14307

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,
    - Do you have the [STAThread] attribute on your Start function ?.
    - If you have, then please create a small example app.
    - The X# assemblies you (may) need to include in your apps are in the Redist folder under the"c:\Program Files (x86)\XSharp" folder. Many people don't like to use MSI, so we decided it was easier to just supply them so you can include them in your own favorite installer.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 30 Apr 2020 17:28 #14318

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello Robert,

    I put the [STAThread] attribute on top of the start function but same result.

    The exception occurs only when I try to open any document - its possible to access the application object and it works with C# - so its a little strange.

    Actually, I was not expecting a solution for this unspecific error but may be some other X# users have experienced this error too. As a workaround we can use a C# class for starting Ms Word.

    Concerning the installer - I don't like msi either - I would prefer a zip file with the assemblies so I don't get a updated program files directory and I definitely don't want any changes to Visual Studio. But there is no option like this at the moment?

    Kind regards,
    Peter

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 30 Apr 2020 17:31 #14319

  • Chris's Avatar

  • Chris


  • Posts: 2109
  • Hi Peter,

    If you can give us a sample that shows the problem, we may be able to find what's causing it. You said it used to work with X# in the past, with which version did it?
    XSharp Development Team
    chris(at)xsharp.eu

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 04 May 2020 15:04 #14352

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello Robert,

    That is not necessary, but thank you for the helpfull offer anyway.

    It works on another computer so the error has some other meanings.

    I was just wondering why a simple COM Interface mixup leads to a "FatalExecutionEngineError " and not an exception that would be more approriate. And it must be somehow X# related because on the same computer it works without a glitch from an C# console app.

    Kind regards,
    Peter

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 04 May 2020 15:18 #14354

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,

    Do the C# app and X# app target the same framework versions ?
    And does it work from an X# app in Core dialect ?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 18 May 2020 12:01 #14634

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello Robert,

    Sorry for the long pause...

    I found out that the COMException only occurs when I choose VisualObject or Vulcan.NET as the dialect for the project.

    It works perfectly (of course) when using the core dialect.

    I also tried several bandol versions from RC 1 to the latest version with the same result.

    Do you have any suggestion how I can zero in on this error?

    Thank you and kind regards,
    Peter

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 19 May 2020 10:26 #14643

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,
    Can you reproduce this in a small app ?

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 19 May 2020 13:32 #14644

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello Robert,

    Yes, I can.

    I have attached a small Visual Studio 2017 project that reproduces the COMException if you choose the "Visual Objects" dialect. When you choose the Core dialect everything should work as supposed to.

    The project includes two Word documents XSharp.docx and XSharp.dotm.

    The WinForm has several buttons for starting Word, loading the document and starting the macro.

    The C# project has the purpose to show that it will work from C#.

    You will only need a recent Microsoft Word like Word 2010.

    Many thanks,
    Peter
    Attachments:

    Please Log in or Create an account to join the conversation.

    Last edit: by pemo18.

    COMException when trying to start Ms Word through COM Interop 20 May 2020 13:18 #14646

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,
    The first parameter to Documents:Open is declared as
    [In] [MarshalAs(UnmanagedType.Struct)] ref object FileName

    When compiling in Core mode this works fine.
    When decompiling the code in C# mode this looks like:
    object FileName = docxPfad;
    .
    .
    documents.Open(ref FileName, .....

    when compiling in the VO/Vulcan dialect this looks like:
    string text = docxPfad;
    .
    .
    documents.Open(ref *(object*)text, .....

    I'll check to see if I can find the reason why this is handled differently.

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 20 May 2020 13:21 #14647

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,

    A quick workaround would be (for the document load):
    LOCAL oDoc := docxPfad AS OBJECT
    wdApp:Documents:Open( REF oDoc ) 


    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 20 May 2020 16:32 #14649

  • robert's Avatar

  • robert


  • Posts: 1846
  • Peter,
    The issue is found and fixed in the next build.
    When running in a non core dialect we are handling default parameters a bit different, since VO and Vulcan allowed to define default parameter values "in the middle", such as
    FUNCTION Test(par1 AS  STRING, par2 := "test" AS STRING,  par3 as LONG) AS LONG
    ..
    RETURN 123
    
    FUNCTION Start AS VOID
    ? Test("Foo",,345)
    

    This is not allowed in C# / Roslyn.
    And the code in which we take care of replacing missing parameters was somehow messing things up for "COM calls".

    Robert
    XSharp Development Team
    The Netherlands

    Please Log in or Create an account to join the conversation.

    COMException when trying to start Ms Word through COM Interop 22 May 2020 15:36 #14678

  • pemo18's Avatar

  • pemo18

  • Topic Author


  • Posts: 37
  • Hello Robert,

    That is very good.

    I know from my past as a VB- and C++ developer in the 90ties that COM interfaces ara ugly (to many pointers) and that the Office interop assemblies and the C# compiler do some tricks to make method calls with many default parameters as simple as possible.

    In the meantime wil we use a C# class lib as a workaround.

    Kind regards,
    Peter

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1