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?
COMException when trying to start Ms Word through COM Interop
COMException when trying to start Ms Word through COM Interop
- Attachments
-
- XSharpWordAutoException_3004.jpg (69.73 KiB) Viewed 563 times
COMException when trying to start Ms Word through COM Interop
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
- 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
The Netherlands
robert@xsharp.eu
COMException when trying to start Ms Word through COM Interop
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
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
COMException when trying to start Ms Word through COM Interop
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?
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
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu
COMException when trying to start Ms Word through COM Interop
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
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
COMException when trying to start Ms Word through COM Interop
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
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
The Netherlands
robert@xsharp.eu
COMException when trying to start Ms Word through COM Interop
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
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
COMException when trying to start Ms Word through COM Interop
Peter,
Can you reproduce this in a small app ?
Robert
Can you reproduce this in a small app ?
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu
COMException when trying to start Ms Word through COM Interop
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
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 69 times
COMException when trying to start Ms Word through COM Interop
Peter,
The first parameter to Documents:Open is declared as
When compiling in Core mode this works fine.
When decompiling the code in C# mode this looks like:
when compiling in the VO/Vulcan dialect this looks like:
I'll check to see if I can find the reason why this is handled differently.
Robert
The first parameter to Documents:Open is declared as
Code: Select all
[In] [MarshalAs(UnmanagedType.Struct)] ref object FileName
When decompiling the code in C# mode this looks like:
Code: Select all
object FileName = docxPfad;
.
.
documents.Open(ref FileName, .....
Code: Select all
string text = docxPfad;
.
.
documents.Open(ref *(object*)text, .....
Robert
XSharp Development Team
The Netherlands
robert@xsharp.eu
The Netherlands
robert@xsharp.eu