Bug 95766 - Using C# code to convert office files to PDF. Error in Activator.CreateInstance.
Summary: Using C# code to convert office files to PDF. Error in Activator.CreateInstance.
Status: RESOLVED NOTABUG
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
5.0.2.2 release
Hardware: IA64 (Itanium) Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-11-12 11:58 UTC by Mahmoud
Modified: 2017-01-04 07:59 UTC (History)
6 users (show)

See Also:
Crash report or crash signature:


Attachments
The sample project. (138.44 KB, application/x-zip-compressed)
2015-11-12 11:58 UTC, Mahmoud
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mahmoud 2015-11-12 11:58:04 UTC
Created attachment 120494 [details]
The sample project.

Using C# and visual studio 2013 to convert office files to PDF.

Trying to create an object of service manager to use it later to convert office files to PDF.
When execute these lines of code 
     var oServiceManagerType = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
     var oServiceManager = Activator.CreateInstance(oServiceManagerType);

But i got this exception:
COMException was caught.
 Creating an instance of the COM component with CLSID {82154420-0FBF-11D4-8313-005004526AB4} from the  IClassFactory failed due to the following error: 80010105 The server threw an exception. (Exception from HRESULT: 0x80010105 (RPC_E_SERVERFAULT)).

Stack Trace:
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at DocumentViewer.LiberOfficeManager.OfficeToPdf.ConvertToPdf(String filePath, String& outputfile) in d:\TestApps\DocumentViewer\LiberOfficeManager\OfficeToPdf.cs:line 34
Comment 1 Mahmoud 2015-11-12 12:57:08 UTC
i need to mention this too.
bug happens with 64 bit processor and 64 bit LibreOffice.
it doesn't happen with 64 bit processor and 32 bit LibreOffice.
Comment 2 DavidO 2015-11-12 13:35:48 UTC
Can you provide the steps to reproduce it?
Comment 3 Mahmoud 2015-11-12 14:17:24 UTC
(In reply to DavidO from comment #2)
> Can you provide the steps to reproduce it?

System Requirements:
 - Windows 8.1 x64
 - LiberOffice 5.0.2.2 x64

run the project in the attachment.
u will get the error.
Comment 4 QA Administrators 2017-01-03 19:37:16 UTC Comment hidden (obsolete)
Comment 5 DavidO 2017-01-04 07:25:59 UTC
I'm trying to reproduce it on my home made build with 2017 RC 64bit.

After installing the LO including ActiveX bits, and runnig the project attachede to this issue, this line is already failing here:

var oServiceManagerType = Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);

with this exception:

+		exception	{"Ungültige Klassenzeichenfolge (Ausnahme von HRESULT: 0x800401F3 (CO_E_CLASSSTRING))"}	System.Exception {System.Runtime.InteropServices.COMException}
Comment 6 DavidO 2017-01-04 07:59:19 UTC
(In reply to DavidO from comment #5)
> I'm trying to reproduce it on my home made build with 2017 RC 64bit.
> 
> After installing the LO including ActiveX bits, and runnig the project
> attachede to this issue, this line is already failing here:
> 
> var oServiceManagerType =
> Type.GetTypeFromProgID("com.sun.star.ServiceManager", true);
> 

Turns out it doesn't hurt to pass WRITE_REGISTRY=1 to the installer:

  msiexec /i LibreOfficeDev_5.4.0.0.alpha0_Win_x64.msi WRITE_REGISTRY=1 /L*v install.log

After re-installing with the command above and building the attached project in 64 bit mode, it works here as expected: ODT file can be comverted to PDF without any issue. I can open the result PDF just fine.