COMException when trying to start Ms Word through COM Interop

This forum is meant for questions and discussions about the X# language and tools
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

COMException when trying to start Ms Word through COM Interop

Post by pemo18 »

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
XSharpWordAutoException_3004.jpg
XSharpWordAutoException_3004.jpg (69.73 KiB) Viewed 381 times
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

COMException when trying to start Ms Word through COM Interop

Post by robert »

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
robert@xsharp.eu
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

COMException when trying to start Ms Word through COM Interop

Post by pemo18 »

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
User avatar
Chris
Posts: 4599
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

COMException when trying to start Ms Word through COM Interop

Post by Chris »

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?
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

COMException when trying to start Ms Word through COM Interop

Post by pemo18 »

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
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

COMException when trying to start Ms Word through COM Interop

Post by robert »

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
robert@xsharp.eu
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

COMException when trying to start Ms Word through COM Interop

Post by pemo18 »

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
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

COMException when trying to start Ms Word through COM Interop

Post by robert »

Peter,
Can you reproduce this in a small app ?

Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
User avatar
pemo18
Posts: 76
Joined: Fri Apr 27, 2018 10:38 am
Location: Germany

COMException when trying to start Ms Word through COM Interop

Post by pemo18 »

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
WordAutoBeispiel.zip
(893.65 KiB) Downloaded 52 times
User avatar
robert
Posts: 4290
Joined: Fri Aug 21, 2015 10:57 am
Location: Netherlands

COMException when trying to start Ms Word through COM Interop

Post by robert »

Peter,
The first parameter to Documents:Open is declared as

Code: Select all

[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:

Code: Select all

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

Code: Select all

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
robert@xsharp.eu
Post Reply